VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "Mscomctl.ocx"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Object = "{B3FB64BF-91F9-11D7-A482-0008A14158BC}#2.22#0"; "itgcontrols.ocx"
Begin VB.Form frmARSalesInvoice 
   BackColor       =   &H00F7D9C2&
   BorderStyle     =   0  'None
   Caption         =   "Form1"
   ClientHeight    =   8070
   ClientLeft      =   840
   ClientTop       =   120
   ClientWidth     =   12465
   BeginProperty Font 
      Name            =   "Tahoma"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MDIChild        =   -1  'True
   ScaleHeight     =   8070
   ScaleWidth      =   12465
   ShowInTaskbar   =   0   'False
   Begin ITGControls.ITGTab SSTab1 
      Height          =   4740
      Left            =   30
      TabIndex        =   36
      Top             =   30
      Width           =   12390
      _ExtentX        =   21855
      _ExtentY        =   8361
      TabCount        =   2
      TabCaption(0)   =   "               Main               "
      TabContCtrlCnt(0)=   13
      Tab(0)ContCtrlCap(1)=   "txtFreightAllow"
      Tab(0)ContCtrlCap(2)=   "txtFreightCharges"
      Tab(0)ContCtrlCap(3)=   "txtTPCGross"
      Tab(0)ContCtrlCap(4)=   "txtTPCName"
      Tab(0)ContCtrlCap(5)=   "ITGCommandButton1"
      Tab(0)ContCtrlCap(6)=   "cmdInvoices"
      Tab(0)ContCtrlCap(7)=   "txtBalance"
      Tab(0)ContCtrlCap(8)=   "txtCredit"
      Tab(0)ContCtrlCap(9)=   "txtDebit"
      Tab(0)ContCtrlCap(10)=   "txtPayment"
      Tab(0)ContCtrlCap(11)=   "txtReturns"
      Tab(0)ContCtrlCap(12)=   "txtGross"
      Tab(0)ContCtrlCap(13)=   "ComunionFrames1"
      TabCaption(1)   =   "               List               "
      TabContCtrlCnt(1)=   1
      Tab(1)ContCtrlCap(1)=   "dtgList"
      TabTheme        =   2
      ActiveTabBackStartColor=   16250865
      ActiveTabBackEndColor=   16243138
      InActiveTabBackStartColor=   16243138
      InActiveTabBackEndColor=   16243138
      InActiveTabForeColor=   -2147483639
      BeginProperty ActiveTabFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty InActiveTabFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      OuterBorderColor=   4210752
      TopLeftInnerBorderColor=   4210752
      BottomRightInnerBorderColor=   4210752
      DisabledTabBackColor=   -2147483633
      DisabledTabForeColor=   -2147483627
      Begin MSDataGridLib.DataGrid dtgList 
         Height          =   4425
         Left            =   -75000
         TabIndex        =   37
         Top             =   315
         Width           =   12390
         _ExtentX        =   21855
         _ExtentY        =   7805
         _Version        =   393216
         AllowUpdate     =   0   'False
         AllowArrows     =   -1  'True
         Appearance      =   0
         HeadLines       =   1
         RowHeight       =   15
         TabAction       =   2
         FormatLocked    =   -1  'True
         BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ColumnCount     =   8
         BeginProperty Column00 
            DataField       =   "cInvNo"
            Caption         =   "Invoice No."
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column01 
            DataField       =   "dDate"
            Caption         =   "Date"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "MM/dd/yyyy"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   3
            EndProperty
         EndProperty
         BeginProperty Column02 
            DataField       =   "cCode"
            Caption         =   "Customer ID"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column03 
            DataField       =   "cType"
            Caption         =   "Invoice Type"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column04 
            DataField       =   "cSMan"
            Caption         =   "Salesman ID"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column05 
            DataField       =   "cMSCode"
            Caption         =   "Market Segment"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column06 
            DataField       =   "nGross"
            Caption         =   "Gross"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column07 
            DataField       =   "cRemarks"
            Caption         =   "Remarks"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         SplitCount      =   1
         BeginProperty Split0 
            AllowRowSizing  =   0   'False
            BeginProperty Column00 
               ColumnAllowSizing=   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   1379.906
            EndProperty
            BeginProperty Column01 
               Locked          =   -1  'True
               ColumnWidth     =   1275.024
            EndProperty
            BeginProperty Column02 
               Locked          =   -1  'True
               ColumnWidth     =   1365.165
            EndProperty
            BeginProperty Column03 
               Locked          =   -1  'True
               ColumnWidth     =   1260.284
            EndProperty
            BeginProperty Column04 
               Locked          =   -1  'True
               ColumnWidth     =   1289.764
            EndProperty
            BeginProperty Column05 
               Locked          =   -1  'True
               ColumnWidth     =   1395.213
            EndProperty
            BeginProperty Column06 
               Alignment       =   1
               Locked          =   -1  'True
               ColumnWidth     =   1305.071
            EndProperty
            BeginProperty Column07 
               Locked          =   -1  'True
               ColumnWidth     =   2459.906
            EndProperty
         EndProperty
      End
      Begin ITGControls.ITGTextBox txtFreightAllow 
         Height          =   285
         Left            =   3675
         TabIndex        =   31
         Top             =   3960
         Width           =   2985
         _ExtentX        =   5054
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BackColor       =   14737632
         LabelBackColor  =   16243138
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Text            =   "0"
         DataType        =   1
         DecimalPlace    =   2
         Label           =   "Freight Allowance"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1350
         TextBoxWidth    =   1575
         LinkForeColor   =   0
      End
      Begin ITGControls.ITGTextBox txtFreightCharges 
         Height          =   285
         Left            =   90
         TabIndex        =   30
         Top             =   3960
         Width           =   2985
         _ExtentX        =   5054
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BackColor       =   14737632
         LabelBackColor  =   16243138
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Text            =   "0"
         DataType        =   1
         DecimalPlace    =   2
         Label           =   "Freight Charges"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1350
         TextBoxWidth    =   1575
         LinkForeColor   =   0
      End
      Begin ITGControls.ITGTextBox txtTPCGross 
         Height          =   285
         Left            =   90
         TabIndex        =   27
         Top             =   3645
         Width           =   2985
         _ExtentX        =   5054
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BackColor       =   14737632
         LabelBackColor  =   16243138
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Text            =   "0"
         DataType        =   1
         DecimalPlace    =   2
         Label           =   "TPC Gross"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1350
         TextBoxWidth    =   1575
         Enabled         =   0   'False
         LinkForeColor   =   0
      End
      Begin ITGControls.ITGTextBox txtTPCName 
         Height          =   285
         Left            =   90
         TabIndex        =   24
         Top             =   3330
         Width           =   6570
         _ExtentX        =   11377
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         LabelBackColor  =   16243138
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Label           =   "TPC Contact"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1350
         TextBoxWidth    =   5160
         LinkForeColor   =   0
      End
      Begin ITGControls.ITGCommandButton ITGCommandButton1 
         Height          =   315
         Left            =   5070
         TabIndex        =   35
         Top             =   4305
         Visible         =   0   'False
         Width           =   1575
         _ExtentX        =   2778
         _ExtentY        =   556
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Caption         =   "Balance Info >>"
      End
      Begin ITGControls.ITGCommandButton cmdInvoices 
         Height          =   315
         Left            =   1470
         TabIndex        =   34
         Top             =   4305
         Visible         =   0   'False
         Width           =   1575
         _ExtentX        =   2778
         _ExtentY        =   556
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Caption         =   "SO Info >>"
      End
      Begin ITGControls.ITGTextBox txtBalance 
         Height          =   285
         Left            =   9720
         TabIndex        =   33
         TabStop         =   0   'False
         Top             =   3960
         Width           =   2415
         _ExtentX        =   4048
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         LabelBackColor  =   16243138
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Text            =   "0"
         DataType        =   1
         DecimalPlace    =   4
         Label           =   "Balance"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1000
         TextBoxWidth    =   1355
         Enabled         =   0   'False
         LinkForeColor   =   0
      End
      Begin ITGControls.ITGTextBox txtCredit 
         Height          =   285
         Left            =   9720
         TabIndex        =   29
         TabStop         =   0   'False
         Top             =   3645
         Width           =   2415
         _ExtentX        =   4048
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BackColor       =   14737632
         LabelBackColor  =   16243138
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Text            =   "0"
         DataType        =   1
         DecimalPlace    =   2
         Label           =   "Credit"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1000
         TextBoxWidth    =   1355
         Enabled         =   0   'False
         LinkForeColor   =   0
      End
      Begin ITGControls.ITGTextBox txtDebit 
         Height          =   285
         Left            =   9720
         TabIndex        =   26
         TabStop         =   0   'False
         Top             =   3330
         Width           =   2415
         _ExtentX        =   4048
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BackColor       =   14737632
         LabelBackColor  =   16243138
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Text            =   "0"
         DataType        =   1
         DecimalPlace    =   2
         Label           =   "Debit"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1000
         TextBoxWidth    =   1355
         Enabled         =   0   'False
         LinkForeColor   =   0
      End
      Begin ITGControls.ITGTextBox txtPayment 
         Height          =   285
         Left            =   6885
         TabIndex        =   32
         TabStop         =   0   'False
         Top             =   3960
         Width           =   2415
         _ExtentX        =   4048
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BackColor       =   14737632
         LabelBackColor  =   16243138
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Text            =   "0"
         DataType        =   1
         DecimalPlace    =   2
         Label           =   "Payment"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1000
         TextBoxWidth    =   1355
         Enabled         =   0   'False
         LinkForeColor   =   0
      End
      Begin ITGControls.ITGTextBox txtReturns 
         Height          =   285
         Left            =   6885
         TabIndex        =   28
         TabStop         =   0   'False
         Top             =   3645
         Width           =   2415
         _ExtentX        =   4048
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BackColor       =   14737632
         LabelBackColor  =   16243138
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Text            =   "0"
         DataType        =   1
         DecimalPlace    =   2
         Label           =   "Returns"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1000
         TextBoxWidth    =   1355
         Enabled         =   0   'False
         LinkForeColor   =   0
      End
      Begin ITGControls.ITGTextBox txtGross 
         Height          =   285
         Left            =   6885
         TabIndex        =   25
         TabStop         =   0   'False
         Top             =   3330
         Width           =   2415
         _ExtentX        =   4048
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         LabelBackColor  =   16243138
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Text            =   "0"
         DataType        =   1
         DecimalPlace    =   4
         Label           =   "Total Amount"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1000
         TextBoxWidth    =   1355
         Enabled         =   0   'False
         LinkForeColor   =   0
      End
      Begin ITGControls.ComunionFrames ComunionFrames1 
         Height          =   2895
         Left            =   0
         Top             =   315
         Width           =   12390
         _ExtentX        =   21855
         _ExtentY        =   5106
         FrameColor      =   4210752
         BackColor       =   16243138
         FillColor       =   16243138
         RoundedCorner   =   0   'False
         Caption         =   "Information"
         Alignment       =   0
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ThemeColor      =   5
         ColorFrom       =   16243138
         ColorTo         =   16250865
         Begin VB.ComboBox cboTerms 
            Appearance      =   0  'Flat
            BackColor       =   &H00FFFFFF&
            Height          =   315
            Left            =   8550
            Style           =   2  'Dropdown List
            TabIndex        =   11
            Top             =   1170
            Width           =   1290
         End
         Begin VB.CommandButton cmdPickSM 
            Enabled         =   0   'False
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   300
            Left            =   2700
            Picture         =   "frmARSalesInvoice.frx":0000
            Style           =   1  'Graphical
            TabIndex        =   17
            Top             =   1815
            Width           =   315
         End
         Begin VB.CommandButton cmdPickCode 
            Enabled         =   0   'False
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   300
            Left            =   2700
            Picture         =   "frmARSalesInvoice.frx":014A
            Style           =   1  'Graphical
            TabIndex        =   5
            Top             =   825
            Width           =   315
         End
         Begin VB.ComboBox cboIntTerms 
            Appearance      =   0  'Flat
            BackColor       =   &H00FFFFFF&
            Height          =   315
            Left            =   8550
            Style           =   2  'Dropdown List
            TabIndex        =   7
            Top             =   825
            Width           =   1290
         End
         Begin VB.ComboBox cboType 
            Appearance      =   0  'Flat
            BackColor       =   &H00FFFFFF&
            Height          =   315
            ItemData        =   "frmARSalesInvoice.frx":0294
            Left            =   7140
            List            =   "frmARSalesInvoice.frx":02A7
            Style           =   2  'Dropdown List
            TabIndex        =   2
            Top             =   510
            Width           =   1485
         End
         Begin VB.ComboBox cboPaymentType 
            Appearance      =   0  'Flat
            BackColor       =   &H00FFFFFF&
            Height          =   315
            Left            =   8550
            Style           =   2  'Dropdown List
            TabIndex        =   15
            Top             =   1485
            Width           =   1290
         End
         Begin VB.CommandButton cmdPickMS 
            Enabled         =   0   'False
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   300
            Left            =   2700
            Picture         =   "frmARSalesInvoice.frx":02EB
            Style           =   1  'Graphical
            TabIndex        =   9
            Top             =   1155
            Width           =   315
         End
         Begin VB.Timer Timer1 
            Interval        =   300
            Left            =   2760
            Top             =   405
         End
         Begin VB.CommandButton cmdPickPD 
            Enabled         =   0   'False
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   300
            Left            =   2700
            Picture         =   "frmARSalesInvoice.frx":0435
            Style           =   1  'Graphical
            TabIndex        =   13
            Top             =   1482
            Width           =   315
         End
         Begin VB.ComboBox cboDocType 
            Appearance      =   0  'Flat
            BackColor       =   &H00FFFFFF&
            Height          =   315
            ItemData        =   "frmARSalesInvoice.frx":057F
            Left            =   10110
            List            =   "frmARSalesInvoice.frx":0581
            Style           =   2  'Dropdown List
            TabIndex        =   3
            Top             =   510
            Width           =   1485
         End
         Begin VB.CommandButton cmdPickPC 
            Enabled         =   0   'False
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   300
            Left            =   2700
            Picture         =   "frmARSalesInvoice.frx":0583
            Style           =   1  'Graphical
            TabIndex        =   21
            Top             =   2145
            Width           =   315
         End
         Begin ITGControls.ITGDateBox dtbDate 
            Height          =   285
            Left            =   4380
            TabIndex        =   1
            Tag             =   "Invoice Date"
            Top             =   510
            Width           =   1275
            _ExtentX        =   2249
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Text            =   ""
            SendKeysTab     =   -1  'True
            Mandatory       =   -1  'True
         End
         Begin ITGControls.ITGTextBox txtInvNo 
            Height          =   285
            Left            =   105
            TabIndex        =   0
            Top             =   540
            Width           =   2550
            _ExtentX        =   4286
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Invoice No."
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1350
            TextBoxWidth    =   1140
            Required        =   -1  'True
         End
         Begin ITGControls.ITGTextBox txtName 
            Height          =   285
            Left            =   3045
            TabIndex        =   6
            TabStop         =   0   'False
            Top             =   855
            Width           =   3735
            _ExtentX        =   6482
            _ExtentY        =   503
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "ITGtext"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   3675
            Enabled         =   0   'False
         End
         Begin ITGControls.ITGTextBox txtCode 
            Height          =   285
            Left            =   105
            TabIndex        =   4
            Top             =   855
            Width           =   2550
            _ExtentX        =   4286
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Customer"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1350
            TextBoxWidth    =   1140
            Required        =   -1  'True
            LinkForeColor   =   16711680
         End
         Begin ITGControls.ITGTextBox txtRemarks 
            Height          =   285
            Left            =   105
            TabIndex        =   23
            Top             =   2430
            Width           =   6675
            _ExtentX        =   11562
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Label           =   "Remarks"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1350
            TextBoxWidth    =   5265
            LinkForeColor   =   0
         End
         Begin ITGControls.ITGTextBox txtSMName 
            Height          =   285
            Left            =   3045
            TabIndex        =   18
            TabStop         =   0   'False
            Top             =   1800
            Width           =   3735
            _ExtentX        =   6482
            _ExtentY        =   503
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "ITGtext"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   3675
            Enabled         =   0   'False
         End
         Begin ITGControls.ITGTextBox txtSMCode 
            Height          =   285
            Left            =   105
            TabIndex        =   16
            Top             =   1797
            Width           =   2550
            _ExtentX        =   4286
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Salesman"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1350
            TextBoxWidth    =   1140
            Required        =   -1  'True
            LinkForeColor   =   16711680
         End
         Begin ITGControls.ITGTextBox txtType 
            Height          =   285
            Left            =   7380
            TabIndex        =   38
            Tag             =   "cboType"
            Top             =   510
            Visible         =   0   'False
            Width           =   1155
            _ExtentX        =   1931
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Mandatory       =   -1  'True
            Label           =   "Invoice Type"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   1095
         End
         Begin ITGControls.ITGTextBox txtPaymentType 
            Height          =   285
            Left            =   8595
            TabIndex        =   39
            Tag             =   "cboPaymentType"
            Top             =   1515
            Visible         =   0   'False
            Width           =   1155
            _ExtentX        =   1931
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Label           =   "Payment Type"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   1095
         End
         Begin ITGControls.ITGTextBox txtIntTerms 
            Height          =   285
            Left            =   8610
            TabIndex        =   40
            Tag             =   "cboIntTerms"
            Top             =   1440
            Visible         =   0   'False
            Width           =   1155
            _ExtentX        =   1931
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Mandatory       =   -1  'True
            Label           =   "Internal Terms"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   1095
         End
         Begin ITGControls.ITGTextBox txtTerms 
            Height          =   285
            Left            =   8580
            TabIndex        =   41
            Tag             =   "cboIntTerms"
            Top             =   1200
            Visible         =   0   'False
            Width           =   1155
            _ExtentX        =   1931
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Mandatory       =   -1  'True
            Label           =   "Internal Terms"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   1095
         End
         Begin ITGControls.ITGTextBox txtMSDesc 
            Height          =   285
            Left            =   3045
            TabIndex        =   10
            TabStop         =   0   'False
            Top             =   1170
            Width           =   3735
            _ExtentX        =   6482
            _ExtentY        =   503
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "ITGtext"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   3675
            Enabled         =   0   'False
         End
         Begin ITGControls.ITGTextBox txtMSCode 
            Height          =   285
            Left            =   105
            TabIndex        =   8
            Top             =   1167
            Width           =   2550
            _ExtentX        =   4286
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Market Segment"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1350
            TextBoxWidth    =   1140
            Required        =   -1  'True
         End
         Begin ITGControls.ITGCommandButton cmdLoad 
            Height          =   300
            Left            =   8535
            TabIndex        =   19
            Top             =   1860
            Visible         =   0   'False
            Width           =   1290
            _ExtentX        =   2275
            _ExtentY        =   529
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Caption         =   "Load Details"
         End
         Begin ITGControls.ITGTextBox txtPDDesc 
            Height          =   285
            Left            =   3045
            TabIndex        =   14
            TabStop         =   0   'False
            Top             =   1485
            Width           =   3735
            _ExtentX        =   6482
            _ExtentY        =   503
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "ITGtext"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   3675
            Enabled         =   0   'False
         End
         Begin ITGControls.ITGTextBox txtPDCode 
            Height          =   285
            Left            =   105
            TabIndex        =   12
            Top             =   1482
            Width           =   2550
            _ExtentX        =   4286
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Product Division"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1350
            TextBoxWidth    =   1140
            Required        =   -1  'True
         End
         Begin ITGControls.ITGTextBox txtDocType 
            Height          =   285
            Left            =   10380
            TabIndex        =   42
            Tag             =   "cboType"
            Top             =   510
            Visible         =   0   'False
            Width           =   1155
            _ExtentX        =   1931
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Mandatory       =   -1  'True
            Label           =   "Invoice Type"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   1095
         End
         Begin ITGControls.ITGTextBox txtPCDesc 
            Height          =   285
            Left            =   3045
            TabIndex        =   22
            TabStop         =   0   'False
            Top             =   2115
            Width           =   3735
            _ExtentX        =   6482
            _ExtentY        =   503
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "ITGtext"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   3675
            Enabled         =   0   'False
         End
         Begin ITGControls.ITGTextBox txtPCCode 
            Height          =   285
            Left            =   105
            TabIndex        =   20
            Top             =   2112
            Width           =   2550
            _ExtentX        =   4286
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Unit Division"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1350
            TextBoxWidth    =   1140
            Required        =   -1  'True
         End
         Begin VB.Label Label6 
            BackColor       =   &H00F7D9C2&
            Caption         =   "Doc Type"
            Height          =   285
            Left            =   9375
            TabIndex        =   48
            Top             =   525
            Width           =   705
         End
         Begin VB.Label Label5 
            BackColor       =   &H00F7D9C2&
            Caption         =   "Type"
            Height          =   285
            Left            =   6345
            TabIndex        =   47
            Top             =   525
            Width           =   600
         End
         Begin VB.Label Label1 
            BackColor       =   &H00F7D9C2&
            Caption         =   "Date"
            Height          =   255
            Left            =   3585
            TabIndex        =   46
            Top             =   540
            Width           =   780
         End
         Begin VB.Label Label2 
            BackColor       =   &H00F7D9C2&
            Caption         =   "Customer Terms"
            Height          =   270
            Index           =   1
            Left            =   7230
            TabIndex        =   45
            Top             =   1200
            Width           =   1365
         End
         Begin VB.Label Label4 
            BackColor       =   &H00F7D9C2&
            Caption         =   "Internal Terms"
            Height          =   285
            Index           =   1
            Left            =   7230
            TabIndex        =   44
            Top             =   855
            Width           =   1365
         End
         Begin VB.Label Label3 
            BackColor       =   &H00F7D9C2&
            Caption         =   "Payment Type"
            Height          =   285
            Left            =   7230
            TabIndex        =   43
            Top             =   1515
            Width           =   1305
         End
      End
   End
   Begin MSComctlLib.StatusBar sbRS 
      Align           =   2  'Align Bottom
      Height          =   285
      Left            =   0
      TabIndex        =   49
      Top             =   7785
      Width           =   12465
      _ExtentX        =   21987
      _ExtentY        =   503
      _Version        =   393216
      BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628} 
         NumPanels       =   5
         BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Object.Width           =   3528
            MinWidth        =   3528
         EndProperty
         BeginProperty Panel2 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
         EndProperty
         BeginProperty Panel3 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Alignment       =   1
            AutoSize        =   1
            Bevel           =   0
            Object.Width           =   8760
            MinWidth        =   2
         EndProperty
         BeginProperty Panel4 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Object.Width           =   3528
            MinWidth        =   3528
         EndProperty
         BeginProperty Panel5 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Object.Width           =   3528
            MinWidth        =   3528
         EndProperty
      EndProperty
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
   End
   Begin ITGControls.ComunionFrames ComunionFrames2 
      Height          =   3000
      Left            =   30
      Top             =   4755
      Width           =   12390
      _ExtentX        =   21855
      _ExtentY        =   5292
      FrameColor      =   4210752
      BackColor       =   16243138
      FillColor       =   16243138
      RoundedCorner   =   0   'False
      Caption         =   "Details"
      Alignment       =   0
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ThemeColor      =   5
      ColorFrom       =   16243138
      ColorTo         =   16250865
      Begin VB.ComboBox cboSI 
         Height          =   315
         Left            =   210
         Style           =   2  'Dropdown List
         TabIndex        =   51
         Top             =   1395
         Visible         =   0   'False
         Width           =   1395
      End
      Begin VB.TextBox txtLongDesc 
         Appearance      =   0  'Flat
         DataField       =   "cLongDesc"
         Height          =   1035
         Left            =   4455
         MultiLine       =   -1  'True
         TabIndex        =   50
         Top             =   930
         Visible         =   0   'False
         Width           =   3930
      End
      Begin MSDataGridLib.DataGrid dtgSI 
         Height          =   2580
         Left            =   0
         TabIndex        =   52
         Top             =   420
         Width           =   12385
         _ExtentX        =   21855
         _ExtentY        =   4551
         _Version        =   393216
         AllowUpdate     =   -1  'True
         AllowArrows     =   -1  'True
         Appearance      =   0
         BackColor       =   16777215
         HeadLines       =   1
         RowHeight       =   15
         TabAcrossSplits =   -1  'True
         TabAction       =   2
         FormatLocked    =   -1  'True
         AllowDelete     =   -1  'True
         BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ColumnCount     =   16
         BeginProperty Column00 
            DataField       =   "cRefNo"
            Caption         =   "Reference No."
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "0.0000"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column01 
            DataField       =   "cWH"
            Caption         =   "Warehouse"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column02 
            DataField       =   "cItemNo"
            Caption         =   "Product ID"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column03 
            DataField       =   "cDesc"
            Caption         =   "Description"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column04 
            DataField       =   "cUnit"
            Caption         =   "Unit"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column05 
            DataField       =   "nQty"
            Caption         =   "Quantity"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column06 
            DataField       =   "nPrice"
            Caption         =   "Price"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.0000"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column07 
            DataField       =   "nAmount"
            Caption         =   "Gross"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.0000"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column08 
            DataField       =   "nTPC"
            Caption         =   "TPC"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column09 
            DataField       =   "nSMCom"
            Caption         =   "Com %"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column10 
            DataField       =   "cBatchID"
            Caption         =   "Batch ID"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column11 
            DataField       =   "nFactor"
            Caption         =   "Factor"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   13321
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column12 
            DataField       =   "nSDiscount"
            Caption         =   "Sales Discount "
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column13 
            DataField       =   "nSAdjustment"
            Caption         =   "Adjustment"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column14 
            DataField       =   "nMargin"
            Caption         =   "Margin"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column15 
            DataField       =   "nSNet"
            Caption         =   "Net Amount"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.0000"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         SplitCount      =   1
         BeginProperty Split0 
            BeginProperty Column00 
               Locked          =   -1  'True
               ColumnWidth     =   1184.882
            EndProperty
            BeginProperty Column01 
               Button          =   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   1484.787
            EndProperty
            BeginProperty Column02 
               Button          =   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   1395.213
            EndProperty
            BeginProperty Column03 
               Button          =   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   2264.882
            EndProperty
            BeginProperty Column04 
               Locked          =   -1  'True
               ColumnWidth     =   629.858
            EndProperty
            BeginProperty Column05 
               Alignment       =   1
               Locked          =   -1  'True
               ColumnWidth     =   1019.906
            EndProperty
            BeginProperty Column06 
               Alignment       =   1
               Locked          =   -1  'True
               ColumnWidth     =   989.858
            EndProperty
            BeginProperty Column07 
               Alignment       =   1
               Locked          =   -1  'True
               ColumnWidth     =   1409.953
            EndProperty
            BeginProperty Column08 
               Alignment       =   1
               Object.Visible         =   0   'False
               ColumnWidth     =   854.929
            EndProperty
            BeginProperty Column09 
               Alignment       =   1
               Locked          =   -1  'True
               Object.Visible         =   0   'False
               ColumnWidth     =   645.165
            EndProperty
            BeginProperty Column10 
               Locked          =   -1  'True
               Object.Visible         =   0   'False
               ColumnWidth     =   1200.189
            EndProperty
            BeginProperty Column11 
               ColumnWidth     =   14.74
            EndProperty
            BeginProperty Column12 
            EndProperty
            BeginProperty Column13 
            EndProperty
            BeginProperty Column14 
            EndProperty
            BeginProperty Column15 
               Locked          =   -1  'True
            EndProperty
         EndProperty
      End
   End
End
Attribute VB_Name = "frmARSalesInvoice"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'IT Group Inc. 2005.09.23

Option Explicit

'Object variables




Private oPrint As New clsPrinting


'Recordset variables
Private WithEvents rsHeader As ADODB.Recordset
Attribute rsHeader.VB_VarHelpID = -1
Private rsDetail As ADODB.Recordset

'Form mode enumeration
Enum eSIMode
    Normal
    AddNewEdit
    Find
End Enum
Public Mode As eSIMode

'Other declarations
Public dtgName As String
Public sBit As String
Private vBM As Variant 'Recordset bookmark variable
Public strNo As String, X As String, sType As String
Public lSystemGeneratedSI As Boolean, lChangedTranNo As Boolean

'ADO Connection variables

Private connHeader As ADODB.Connection
Private connDetail As ADODB.Connection

Private nLimit, nAR, nARPastDue, nPDC, nHold, nBounced, nSOAmtLeft, nLimitBalance As Double 'For credit limit purposes
Private lOverride As Boolean

'Security Acess Level variables
Public lACNew As Boolean
Public lACEdit As Boolean
Public lACDelete As Boolean
Public lACPost As Boolean
Public lACCancel As Boolean
Public lACPrint As Boolean

Private Sub cboDocType_Click()
On Error GoTo TheSource
    txtDocType = Trim(cboDocType)
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(txtInvNo) = "" Then Exit Sub
    If rsHeader.Status <> adRecNew Then
        If ((Format(Right(txtInvNo, 5) - 1, X))) <> (strNo) Then Exit Sub
    End If
    GetCtrlNo
TheSource:
    Exit Sub
End Sub

Private Sub cboDocType_KeyPress(KeyAscii As Integer)
    SendKeysTab KeyAscii
End Sub

Private Sub cboIntTerms_Click()
    txtIntTerms = Trim(cboIntTerms)
End Sub

Private Sub cboIntTerms_KeyPress(KeyAscii As Integer)
    SendKeysTab KeyAscii
End Sub

Private Sub cboPaymentType_Click()
    txtPaymentType = Trim(cboPaymentType)
End Sub

Private Sub cboPaymentType_KeyPress(KeyAscii As Integer)
    SendKeysTab KeyAscii
End Sub

Private Sub cboPaymentType_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If rsDetail.RecordCount = 0 Then TBNewLine
End Sub

Private Sub cboSI_Click()
    If dtgSI.Col = 1 Then
        rsDetail!cWH = cboSI
    End If
End Sub

Private Sub cboSI_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 13 Then
        If dtgSI.Col = 1 Then
            rsDetail!cWH = cboSI
            cboSI.Visible = False
            dtgSI.Col = 5
            dtgSI.Columns(5).Value = rsDetail!nQty
            dtgSI.SetFocus
        End If
    ElseIf KeyCode = vbKeyEscape Then
        cboSI.Visible = False
    End If
End Sub

Private Sub cboSI_LostFocus()
    cboSI.Visible = False
End Sub

Private Sub cboTerms_Click()
    txtTerms = Trim(cboTerms)
End Sub

Private Sub cboTerms_KeyPress(KeyAscii As Integer)
    SendKeysTab KeyAscii
End Sub

Private Sub cboType_Click()
    txtType = Trim(cboType)
End Sub
    
Private Sub cboType_KeyPress(KeyAscii As Integer)
    SendKeysTab KeyAscii
End Sub

Private Sub cboType_LostFocus()
On Error Resume Next
    If UCase(txtType) = "AUTO-INVOICE" Then
        MsgBox "Invoice type Auto-Invoice are auto-generated.", vbInformation, "ComUnion"
        cboType.SetFocus
    End If
End Sub

'Load picklist
Private Sub cmdLoad_Click()
    
    If Mode <> AddNewEdit Then Exit Sub
    
    If Trim(cboType) = "" Then
        MsgBox "Please select transaction type.", vbInformation, "ComUnion"
        cboType.SetFocus
        Exit Sub
    End If
    
    If Trim(txtCode) = "" Then
        MsgBox "Please input Customer ID.", vbInformation, "ComUnion"
        txtCode.SetFocus
        Exit Sub
    End If
    
    RepName = Trim(txtCode)
    
    'Reference Type
    Select Case Trim(cboType)
        Case "Invoice" 'Direct to SO
            sCondition = "'" & COID & "', '" & txtCode & "', ' and a.cType = ''Regular'''"
            frmRefList.mType = Sales_Invoice
        Case "Jobber" 'Direct to SO
            sCondition = "'" & COID & "', '" & txtCode & "', ' and a.cType = ''Jobber'''"
            frmRefList.mType = Sales_Jobber
        Case "Exhibit" 'Direct to SO
            sCondition = "'" & COID & "', '" & txtCode & "', ' and a.cType = ''Exhibit'''"
            frmRefList.mType = Sales_Exhibit
        Case "Invoice w/ DR" 'With reference DR
            sCondition = "'" & COID & "', '" & txtCode & "', ' and a.cType in (''Issues'',''Sales'')'"
            frmRefList.mType = Sales_Delivery_Receipt
        Case "Sample/Demo" 'With reference DR (Sample/Demo)
            sCondition = "'" & COID & "', '" & txtCode & "', ' and a.cType = ''Sample/Demo'''"
            frmRefList.mType = Sales_SampleDemo
        Case "Walk-in" 'Direct to SO
            sCondition = "'" & COID & "', '" & txtCode & "', ' and a.cType = ''Walk-in'''"
            frmRefList.mType = Sales_WalkIn
'        Case "Consignment" 'Directly from SO
'            sCondition = "'" & COID & "', '" & txtCode & "', ' and a.cType = ''For Sales-Con'''"
'            frmRefList.mType = Sales_Consignment
        Case "Corporate"
            sCondition = "'" & COID & "', '" & txtCode & "', ' and a.cType = ''Corporate'''"
            frmRefList.mType = Sales_Corporate
    End Select
    If frmRefList.Visible = False Then frmRefList.Show vbModal
End Sub

Private Sub cmdPickCode_Click()
    If lPickListActive Then Exit Sub
    sFilterString = Trim(txtCode)
    With frmITGPicker
        .zType = QCustomer
        Select Case UCase(Trim(cboType))
            Case "CORPORATE"
                .zType = QClientSupplier
            Case Else
        End Select
        .Condition = "where cCompanyID = '" & COID & "'"
        .Show vbModal
        txtCode = .zCode
    End With
End Sub

Private Sub cmdPickMS_Click()
    If lPickListActive Then Exit Sub
    sFilterString = Trim(txtMSCode)
    frmITGPicker.zType = QMarketSegment
    'added condition
    frmITGPicker.Condition = "where cCompanyID = '" & COID & "'"
    
    frmITGPicker.Show vbModal
    txtMSCode = frmITGPicker.zCode
    txtMSDesc = frmITGPicker.zName
    If Trim(txtMSDesc) <> "" Then SendKeys "{Tab}"
End Sub

Private Sub cmdPickPC_Click()
    If lPickListActive Then Exit Sub
    sFilterString = Trim(txtPCCode)
    frmITGPicker.zType = QProfitCenter
    'added condition
    frmITGPicker.Condition = "where cCompanyID = '" & COID & "'"
    
    frmITGPicker.Show vbModal
    txtPCCode = frmITGPicker.zCode
    txtPCDesc = frmITGPicker.zName
    If Trim(txtPCDesc) <> "" Then SendKeys "{Tab}"
End Sub

Private Sub cmdPickPD_Click()
    If lPickListActive Then Exit Sub
    frmITGPicker.zType = QProductDivision
    'added condition
    frmITGPicker.Condition = "where cCompanyID = '" & COID & "'"
    
    frmITGPicker.Show vbModal
    txtPDCode = frmITGPicker.zCode
    txtPDDesc = frmITGPicker.zName
    If Trim(txtPDDesc) <> "" Then SendKeys "{Tab}"
End Sub

Private Sub cmdPickSM_Click()
    If lPickListActive Then Exit Sub
    sFilterString = Trim(txtSMCode)
    frmITGPicker.zType = QSalesman
    'added condition
    frmITGPicker.Condition = "where cCompanyID = '" & COID & "'"
    
    frmITGPicker.Show vbModal
    txtSMCode = frmITGPicker.zCode
    txtSMName = frmITGPicker.zName
    If Trim(txtSMName) <> "" Then SendKeys "{Tab}"
End Sub

Private Sub DataGrid1_Click()

End Sub

Private Sub dtgList_HeadClick(ByVal ColIndex As Integer)
    SortGrid dtgList, ColIndex, rsHeader
End Sub

Private Sub dtgSI_AfterColUpdate(ByVal ColIndex As Integer)
    If Mode <> AddNewEdit Then Exit Sub
    Select Case ColIndex
        Case 5
            ComputeAmount
            ComputeGross
            ComputeTotal
        Case 6
            ComputeAmount
            ComputeGross
            ComputeTotal
        Case 7
            ComputeAmount
            ComputeGross
            ComputeTotal
        Case 8
            ComputeTotal
        Case 12
            ComputeAmount
            ComputeGross
            ComputeTotal
        Case 13
            ComputeAmount
            ComputeGross
            ComputeTotal
        Case 14
            ComputeAmount
            ComputeGross
            ComputeTotal
    End Select
End Sub

Private Sub dtgSI_ButtonClick(ByVal ColIndex As Integer)
    If ColIndex = 3 Then
        Call MoveText(txtLongDesc, dtgSI, dtgSI.Columns(3))
        txtLongDesc = rsDetail!cLongDesc & ""
    End If
    If Mode = AddNewEdit Then 'Exit Sub
        Select Case ColIndex
            Case 1
                Call LoadComboValues(cboSI, "cWH", "WHSE", "WHERE cCompanyID = '" & COID & "'")
                Call MoveCombo(cboSI, dtgSI, dtgSI.Columns(1))
                ComboLoadValue cboSI, Trim(dtgSI.Columns(1).Text)
            Case 2
                If rsHeader!cType = "Consignment" Then
                    If lPickListActive Then Exit Sub
                    sFilterString = Trim(dtgSI.Columns(2).Text)
                    frmITGPicker.zType = QProduct
                    frmITGPicker.Condition = "where cCompanyID = '" & COID & "'"
                    frmITGPicker.Show vbModal
                    If rsHeader!cType <> Trim("Consignment") Then
                        rsDetail!cBarcodeID = frmITGPicker.zCode
                    End If
                    rsDetail!cItemNo = GetValueFrTable("cItemNo", "ITEM", "cPartNo = '" & frmITGPicker.zCode & "'")
                    rsDetail!cDesc = frmITGPicker.zName
                    If Trim(Trim(dtgSI.Columns(2).Text)) <> "" Then SendKeys "{Tab}"
                Else
                    If Trim(dtgSI.Columns(2).Text) <> "" Then
'                        frmMaintProduct.Show
'                        frmMaintProduct.ZOrder
'                        frmMaintProduct.ShowForm LTrim(RTrim(dtgSI.Columns(2).Text))
                    End If
                End If
        End Select
    Else
        Select Case ColIndex
        Case 2
            If Mode <> Find Then
                If Trim(dtgSI.Columns(2).Text) <> "" Then
'                    frmMaintProduct.Show
'                    frmMaintProduct.ZOrder
'                    frmMaintProduct.ShowForm LTrim(RTrim(dtgSI.Columns(2).Text))
                End If
            End If
        End Select
    End If
End Sub

'Set the datagrid as active control
Private Sub dtgSI_Click()
    If Mode = AddNewEdit Then dtgName = dtgSI.Name
End Sub

Private Sub dtgSI_Error(ByVal DataError As Integer, Response As Integer)
    Response = 0
End Sub

Private Sub dtgSI_KeyDown(KeyCode As Integer, Shift As Integer)
    If Mode <> AddNewEdit Then Exit Sub
    If (Shift = vbCtrlMask And KeyCode = 45) Then
        TBNewLine
    ElseIf (Shift = vbCtrlMask And KeyCode = 46) Then
        TBDeleteLine
    ElseIf (Shift = vbCtrlMask And KeyCode = 83) Then
        TBSave
    End If
End Sub

Private Sub dtgSI_KeyPress(KeyAscii As Integer)
    
    If Mode <> AddNewEdit Then Exit Sub
    If rsDetail.RecordCount = 0 Then Exit Sub
    If KeyAscii = 39 Then KeyAscii = 0 'Apostrophe {'}
    If KeyAscii = 13 Then
        Select Case dtgSI.Col
            Case 5
                dtgSI_AfterColUpdate (5)
            Case 6
                dtgSI_AfterColUpdate (6)
            Case 7
                dtgSI_AfterColUpdate (7)
                SendKeys "{Tab}"
            Case 12
                dtgSI_AfterColUpdate (12)
                SendKeys "{Tab}"
            Case 13
                dtgSI_AfterColUpdate (13)
                SendKeys "{Tab}"
            Case 14
                dtgSI_AfterColUpdate (14)
                SendKeys "{Tab}"
            Case Else
                SendKeys "{Tab}"
        End Select
    Else: KeyAscii = Asc(UCase(Chr(KeyAscii)))        'All Upper Case String
    End If

End Sub

'Right click menu popup
Private Sub dtgSI_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Mode <> AddNewEdit Then Exit Sub
    If Button = 2 Then
        dtgName = dtgSI.Name
        PopupMenu ITGLedgerMain.mnuDetail
    End If
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Dim iKey As Integer
    iKey = ToolbarIndex(KeyCode, Shift)
    If iKey <> 0 Then
        If ITGLedgerMain.tbrMain.Buttons(iKey).Enabled = True Then
            ToolbarFunction iKey
        End If
    End If
End Sub

'Set Your Object
Private Sub Form_Load()
    
    Set FrmName = Me
    FormSetup
    
    AcessBit Me, GetValueFrTable("AccessLevel", "SEC_ACCESSLEVEL", "RoleID = '" & SecUserRole & "' AND [Module] = 'AR01'")
    
    Set rsHeader = New ADODB.Recordset
    Set rsDetail = New ADODB.Recordset
    

    'Load combobox values
    Call LoadComboValues(cboDocType, "cValue", "PARAMETER_USER", "WHERE cType = 'SIDOCTYPE' AND cCompanyID = '" & Trim(COID) & "'")
    Call LoadComboValues(cboTerms, "cParamName", "PARAMETER_USER", "WHERE cType = 'TERMS' AND cCompanyID = '" & Trim(COID) & "'", "nOrder")
    Call LoadComboValues(cboIntTerms, "cParamName", "PARAMETER_USER", "WHERE cType = 'TERMS' AND cCompanyID = '" & Trim(COID) & "'", "nOrder")
    Call LoadComboValues(cboPaymentType, "cValue", "PARAMETER_SYSTEM", "WHERE cType = 'SOPAYTYPE'")
    
    Call ColumnVisible("Barcode ID", dtgSI)
    
    FormLocking True
    FormSearch True
    SearchObj True
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, , , , , , , , , True, , , True
    BitVisible ITGLedgerMain.tbrMain, True, True
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = True

    'System generated si number
    'lSystemGeneratedsi = GetValueFrTable("lBit", "SYSTEM_OPTION", "cCode = 'OTHERS_AUTOTRANNO_SO' ")
    lSystemGeneratedSI = True

    Mode = Find
    txtInvNo.Locked = False
    
End Sub

'Activate your Toolbar Mode
Private Sub Form_Activate()
    Set FrmName = Me
    TBBitReload
End Sub

'Release your Object
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
    If Mode = AddNewEdit Then
        MsgBox "Unable to close. You are in Add/New/Edit mode." & vbCr & _
            " Must Save or Undo", vbCritical, Me.Caption
        Cancel = True
        Exit Sub
    End If
    
    CloseMenuTab ITGLedgerMain
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , , , , , , , True
    BitVisible ITGLedgerMain.tbrMain
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = False

    
    
    
    
    Set oPrint = Nothing
    Set rsHeader = Nothing
    Set rsDetail = Nothing
    Set connHeader = Nothing
    Set connDetail = Nothing
    
    Set frmARSalesInvoice = Nothing

    lCloseWindow = True
    
End Sub

'Add new record to the recordset
Public Sub TBNew()

    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True
    txtInvNo.BackColor = &HE0FFFF
    Mode = AddNewEdit

    If rsHeader.State <> adStateOpen Then
        OpenNewConnection connDetail
        OpenNewConnection connHeader
        OpenRecordsetWithCN rsDetail, "*", "SALES_T", connDetail, "WHERE 1 = 0"
        OpenRecordsetWithCN rsHeader, "*", "SALES", connHeader, "WHERE 1 = 0"
        SetDataSource
        SetDataField
    Else: vBM = rsHeader.Bookmark
    End If

    rsHeader.AddNew
    rsHeader!cCompanyID = COID
    rsHeader!dDate = Date
    rsHeader!cType = "Invoice w/ DR"
    cboDocType.ListIndex = 0
    rsHeader!cPayType = "Credit"
    rsHeader!cPCCode = sDivision
    
    txtReturns = "0.00"
    txtCredit = "0.00"
    txtDebit = "0.00"
    txtPayment = "0.00"
    txtBalance = "0.00"

    Set FrmName = Me
    FormLocking False
    ClrRequired &HC0&
    txtGross.Locked = True
    SSTab1.ActiveTab = 0
    txtInvNo.SetFocus

    'system generated si no
    If lSystemGeneratedSI Then GetCtrlNo
    '--------------------------
    
End Sub

'Undo all changes to the recordset
Public Sub TBUndoAll()
On Error GoTo ErrorHandler

    Mode = Normal
    
    If rsHeader.Status = adRecNew Then TBUndoCurrent
    
    rsHeader.CancelBatch adAffectAll
    rsDetail.CancelBatch adAffectAll
    
    UnbindControls
    
    If rsHeader.RecordCount <> 0 Then rsHeader.Bookmark = vBM
    
    Set FrmName = Me
    FormLocking True
    
    If rsHeader.RecordCount <> 0 Then
        BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , lACCancel, , , True, True, lACPrint, True, True
    Else
        RSZero
        Mode = Find
    End If
    
    EditDetail False

    sbRS.Panels(2) = ""
    
    SetDataSource
    SetDataField

ErrorHandler:
    cboSI.Visible = False
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217842 Then 'Operation was cancelled. (Error returned by ITGDateBox)
        TBUndoAll
    End If

End Sub

'Undo changes on the current record
Public Sub TBUndoCurrent()
On Error GoTo ErrorHandler

    GetChild
    If rsHeader.Status = adRecNew Then
        rsDetail.CancelBatch adAffectAll
        rsHeader.CancelUpdate
    Else
        rsHeader.CancelBatch adAffectCurrent
        rsDetail.CancelBatch adAffectAll
    End If
   
    If rsHeader.RecordCount = 0 Then RSZero
    
ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217842 Then 'Operation was cancelled. (Error returned by ITGDateBox)
        TBUndoCurrent
    End If

End Sub

'Save all changes
Public Sub TBSave()
Dim OKUpdate As Boolean
Dim lNew As Boolean
On Error GoTo ErrHandler

    'Audit Trail
    lBoolean = False
    If rsHeader.Status = adRecNew Then
        lBoolean = True
        If GetValueFrTable("lBit", "SYSTEM_OPTION", "cCode = 'CL_CHECKING_SI'") Then
            If Not lOverride Then
                If (UCase(Trim(cboType)) = "INVOICE") Then
                    If CDbl(txtGross) > (nLimitBalance) Then
                        MsgBox "Invoice Gross exceeds the allowable credit limit balance." & vbCr & _
                                "Transaction cannot be saved.", vbInformation, "ComUnion"
                        Exit Sub
                    End If
                End If
            End If
        End If
    End If
    
    If Not MandatoryOK Then Exit Sub
    
    'System generated si no
    If rsHeader.Status = adRecNew Then
        
        If GetValueFrTable("lFormat", "PARAMETER_USER", "cValue = '" & Trim(cboDocType) & "' AND cType = 'SIDOCTYPE' ") = True Then
            If Not CheckCtrlNo Then Exit Sub
        End If
        lNew = True
    End If
    '----------------------
    
    OKUpdate = False
    cn.BeginTrans
    connHeader.BeginTrans
    connDetail.BeginTrans
    
    rsHeader.UpdateBatch adAffectAll
    rsDetail.UpdateBatch adAffectAll
    
    If (UCase(Trim(cboType)) = "INVOICE") Or _
            (UCase(Trim(cboType)) = "CONSIGNMENT") Or _
            (UCase(Trim(cboType)) = "CORPORATE") Or _
            (UCase(Trim(cboType)) = "JOBBER") Or _
            (UCase(Trim(cboType)) = "EXHIBIT") Or _
            (UCase(Trim(cboType)) = "For Sales-Con") Then
        If Not SIToDR Then GoTo ErrHandler
    Else 'If UCase$(Trim$(cboType)) = "INVOICE W/ DR" Then
        If Not UpdateDRSI Then GoTo ErrHandler
    End If
    
    If (UCase(Trim(cboType)) = "JOBBER") Then
        If Not SIToWRR Then GoTo ErrHandler
        If Not SIToAR Then GoTo ErrHandler
    End If

    cn.CommitTrans
    connHeader.CommitTrans
    connDetail.CommitTrans
    OKUpdate = True
    
    Set FrmName = Me
    FormLocking True
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , lACCancel, , , True, True, lACPrint, True, True
    Mode = Normal
        
    MsgBox "Record/s successfully saved.", vbInformation, "ComUnion"
    sbRS.Panels(2) = ""
    
    'Audit trail
    UpdateLogFile "Sales Invoice", Trim(txtInvNo), IIf(lBoolean, "Inserted", "Updated")
    
    'Update GL Activity
    UpdateGLA "Update", "SI", Trim(txtInvNo)
    
    If lNew = True Then
        If lSystemGeneratedSI = True Then UpdateCtrlNo
    End If
    '----------------------
    
    EditDetail False
    
ErrHandler:
    cboSI.Visible = False
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217864 Then
        OKUpdate = True
        cn.RollbackTrans
        connHeader.RollbackTrans
        connDetail.RollbackTrans
        MsgBox "Record cannot be updated. Some values may have been changed by other user/s since last read." & vbCr & _
                "Records will be automatically refreshed. All changes made to the record will be gone upon refresh.", vbInformation, "ComUnion"
        vBookMark = rsHeader.Bookmark
        UnbindControls
        rsHeader.Requery
        rsDetail.Requery
        BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , lACCancel, , , True, True, lACPrint, True
        Mode = Normal
        If rsHeader.RecordCount <> 0 Then
            Set FrmName = Me
            FormLocking True
            SetDataField
            SetDataSource
            rsHeader.Bookmark = vBookMark
        Else: RSZero
        End If
    End If
    If Not OKUpdate Then
        MsgBox "Transaction update failed.", vbInformation, "ComUnion"
        cn.RollbackTrans
        connHeader.RollbackTrans
        connDetail.RollbackTrans
        ErrorLog err.Number, err.Description, Me.Name 'Error log
    End If

End Sub

'Sets the form & recorset to add/edit mode
Public Sub TBEdit()
    If rsHeader!lCancelled = True Then
        MsgBox "Transaction was already cancelled. Edit is not allowed.", vbExclamation, "ComUnion"
        Exit Sub
    End If
    If Not AllowEdit Then Exit Sub
    Mode = AddNewEdit
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True
    Set FrmName = Me
    FormLocking False
    ClrRequired &HC0&
    txtGross.Locked = True
    txtInvNo.Locked = True
    EditDetail True
    SSTab1.ActiveTab = 0
    dtbDate.SetFocus
    vBM = rsHeader.Bookmark
End Sub

'Delete record
Public Sub TBDelete()
On Error GoTo ErrorHandler

    sID = Trim(txtInvNo)
    
    If rsHeader.RecordCount = 0 Then Exit Sub

    If rsHeader!lCancelled = True Then
        MsgBox "Transaction was already cancelled. Deletion is not allowed.", vbExclamation, "ComUnion"
        Exit Sub
    End If
    
    If MsgBox("Are you sure you want to delete this record?", vbQuestion + vbYesNo, "ComUnion") = vbNo Then Exit Sub

    If Not AllowDelete("delete") Then Exit Sub
    
    'Update GL Activity
    UpdateGLA "Delete", "SI", Trim(txtInvNo)
    
    GetChild
    If rsDetail.RecordCount <> 0 Then
        rsDetail.MoveFirst
        Do Until rsDetail.RecordCount = 0
            rsDetail.Delete adAffectCurrent
            If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
        Loop
    End If
    
    'Audit trail
    UpdateLogFile "Sales Invoice", Trim(txtInvNo), "Deleted"

    rsHeader.Delete adAffectCurrent
    
    rsDetail.UpdateBatch adAffectAll
    rsHeader.UpdateBatch adAffectAll
    MsgBox "Invoice " & Trim(sID) & " has been deleted", vbInformation, "ComUnion"
        
    TBPrevRec

    Mode = Normal

    If rsHeader.RecordCount = 0 Then
        RSZero
    End If

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217864 Then
        cn.Execute "DELETE SALES_T WHERE cInvNo = '" & sID & "' AND cCompanyID = '" & COID & "'"
        cn.Execute "DELETE SALES WHERE cInvNo = '" & sID & "' AND cCompanyID = '" & COID & "'"
        Resume Next
    End If

End Sub

'Search using the frmITGSearch
Public Sub TBFind()
    Mode = Normal
    txtInvNo.Locked = True
    frmITGSearch.Show 'vbModal
End Sub

'Search using the recordset primary key
Public Sub TBFindPrimary()
Dim sTemp As String
If Mode = Find Then
    FormWaitShow App.Path & "\Transmit.avi", "Loading data . . ."
        
    OpenNewConnection connHeader
    OpenNewConnection connDetail

    Set rsHeader = Nothing
    Set rsDetail = Nothing
    Set rsHeader = New ADODB.Recordset
    Set rsDetail = New ADODB.Recordset

    sTemp = Trim$(GetSearchString)
    If sTemp = "ERROR" Then
        MsgBox "Only Allows A - Z, 0 - 9, '.', ',' and %(wildcard)", vbExclamation, ""
        BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, , , , , , , , , True, , , True
        txtInvNo.Locked = False
        txtInvNo.SetFocus
        Exit Sub
    End If
    
    OpenRecordsetWithCN rsHeader, "*", "SALES", connHeader, IIf(sTemp = "", "", " WHERE " & sTemp)
    'OpenRecordsetWithCN rsDetail, "*", "SALES_T", connDetail
             
    OpenRecordsetWithCN rsDetail, "*", "SALES_T", connDetail, IIf(sTemp = "", "", " WHERE cInvNo IN (SELECT cInvNo FROM SALES WHERE " & sTemp & ")")
    
    Set FrmName = Me
    FormLocking True

      If rsHeader.RecordCount = 0 Then
        FormWaitHide
        MsgBox "No matching record/s found.", vbInformation, "ComUnion Search"
        RSZero
        FormSearch True
        SearchObj True
        Mode = Find
        Exit Sub
    End If
    SetDataSource
    SetDataField
    txtInvNo.BackColor = &HE0FFFF
    Mode = Normal
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , lACCancel, , , True, True, lACPrint, True, True

    FormWaitHide
Else
    RSZero
    FormSearch True
    SearchObj True
    Mode = Find
      
End If

End Sub

Public Sub TBAccountAffected()
If rsHeader!lCancelled = 0 Then
    RepName = "SALES"
    frmAccountAffected.mModuleType = KSALES
    frmAccountAffected.mRefPK = txtInvNo.Text
    frmAccountAffected.Show vbModal
End If
End Sub

'Reload menu buttons (do not delete this sub)
Public Sub TBBitReload()
    BitVisible ITGLedgerMain.tbrMain, True, True
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = True
    BitReload ITGLedgerMain, Me, ITGLedgerMain.tbrMain, sBit
    Set FrmName = Me
    dtgName = dtgSI.Name
End Sub

'Close active window
Public Sub TBCloseWindow()
    Unload Me
End Sub

'Move first
Public Sub TBFirstRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MoveFirst rsHeader
    
End Sub

'Move previuos
Public Sub TBPrevRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MovePrevious rsHeader
    
End Sub

'Move next
Public Sub TBNextRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MoveNext rsHeader

End Sub

'Move last
Public Sub TBLastRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MoveLast rsHeader
    
End Sub

'Add new line to the detail recordset
Public Sub TBNewLine()
    If Trim(cboType) = "" Then
        MsgBox "Please select transaction type.", vbExclamation, "ComUnion"
        Exit Sub
    Else
        If (Trim(cboType) = "Consignment") Then
            If rsHeader!cInvNo = "" Then Exit Sub

            If Trim(txtName) = "" Then
                MsgBox "Please pick client.", vbExclamation, "ComUnion"
                Exit Sub
            End If

            If dtgName = "dtgSI" Then
                rsDetail.AddNew
                rsDetail!cCompanyID = COID
                rsDetail!cInvNo = Trim(rsHeader!cInvNo)
                dtgSI.Col = 1
                dtgSI.Columns(1).Value = ""
                GetChild
                If rsDetail.RecordCount <> 0 Then rsDetail.MoveLast
                dtgSI.SetFocus
            End If
            dtgSI.Columns(4).Locked = True
            dtgSI.Columns(5).Locked = True
            dtgSI.Columns(6).Locked = True
            dtgSI.Columns(7).Locked = False
            dtgSI.Columns(4).Visible = False
            dtgSI.Columns(5).Visible = False
            dtgSI.Columns(6).Visible = False
            dtgSI.Columns(1).Text = GetValueFrTable("cWH", "WHSE", "cCode = '" & rsHeader!cCode & "'")
            rsDetail!nSDiscount = 0
            rsDetail!nSAdjustment = 0
            rsDetail!nMargin = 0
            dtgSI.Col = 2
        Else
            cmdLoad_Click 'Load details from list
            dtgSI.Columns(4).Visible = True
            dtgSI.Columns(5).Visible = True
            dtgSI.Columns(6).Visible = True
        End If
    End If

    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True
End Sub

'Delete line in the detail recordset
Public Sub TBDeleteLine()
On Error GoTo ErrorHandler

    If dtgName = dtgSI.Name Then
        If rsDetail.RecordCount = 0 Then Exit Sub
        vBookMark = dtgSI.Bookmark
        GetChild
        dtgSI.Bookmark = vBookMark
        rsDetail.Delete adAffectCurrent
        ComputeTotal
    End If
    GetChild

    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

'Undo All
Public Sub TBUndoLineAll()
On Error GoTo ErrorHandler

    MsgBox "Unavailable on " & Me.Name

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

'Undo current line
Public Sub TBUndoLineCurrent()
    MsgBox "Unavailable on " & Me.Name
End Sub

'Post current record
Public Sub TBPostRecord()
    MsgBox "Unavailable on " & Me.Name
End Sub

'Cancel current record
Public Sub TBCancelRecord()
On Error GoTo ErrorHandler
    
    If rsHeader.RecordCount = 0 Then Exit Sub

    If rsHeader!lCancelled = True Then
        MsgBox "Transaction was already cancelled.", vbExclamation, "ComUnion"
        Exit Sub
    End If
    
    If MsgBox("Are you sure you want to cancel this record?", vbQuestion + vbYesNo, "ComUnion") = vbNo Then Exit Sub

    If Not (AllowDelete("cancel")) Then Exit Sub
    
    'Audit trail
    UpdateLogFile "Sales Invoice", Trim(txtInvNo), "Cancelled"

    'Update GL Activity
    UpdateGLA "Delete", "SI", Trim(txtInvNo)
    
    cn.Execute ("UPDATE SALES SET lCancelled = 1 WHERE cInvNo = '" & Trim(txtInvNo) & "' AND cCompanyID = '" & COID & "'")
    
    sbRS.Panels(5) = "CANCELLED"
    Mode = Normal
    
    rsHeader!lCancelled = True
    rsHeader.UpdateBatch adAffectAll

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

'Print
Public Sub TBPrintRecord()
    If Trim(txtInvNo) = "" Then Exit Sub
    RepName = GetValueFrTable("cParamName", "PARAMETER_USER", "cType = 'SIDOCTYPE' AND cValue = '" & Trim(cboDocType) & "'")
    cModule = "Sales_Invoice"
    oPrint.PrintReceipt Trim(txtInvNo)
End Sub

'Sets the data source of the controls
Sub SetDataSource()
    Set FrmName = Me
    BindControls rsHeader
    Set dtgList.DataSource = rsHeader
    Set dtgSI.DataSource = rsDetail
    Set txtLongDesc.DataSource = rsDetail
    
End Sub

'Sets the data field for every bounded controls
Sub SetDataField()
    With rsHeader
        txtInvNo.DataField = !cInvNo
        dtbDate.DataField = !dDate
        txtType.DataField = !cType
        txtDocType.DataField = !cdoctype
        txtCode.DataField = !cCode
        txtMSCode.DataField = !cMSCode
        txtPDCode.DataField = !cPDCode
        txtSMCode.DataField = !cSMan
        txtPCCode.DataField = !cPCCode
        txtRemarks.DataField = !cRemarks
        txtIntTerms.DataField = !cIntTerm
        txtTerms.DataField = !cTerm
        txtPaymentType.DataField = !cPayType
        txtGross.DataField = !nGross
        txtTPCName.DataField = !cTPCName
        txtTPCGross.DataField = !nTPCGross
        txtFreightCharges.DataField = !nFreightCharges
        txtFreightAllow.DataField = !nFreightAllow
'        txtSAdjustment.DataField = !nSAdjustment
'        txtSDiscount.DataField = !nSDiscount
    End With
End Sub





Private Sub rsHeader_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
On Error GoTo ErrorHandler

    If Not (rsHeader.EOF) Or Not (rsHeader.BOF) Then
        'Status bar setup
        sbRS.Panels(1) = "Record: " & IIf((rsHeader.AbsolutePosition = -2), "0", rsHeader.AbsolutePosition) & "/" & rsHeader.RecordCount

        If rsHeader.Status <> adRecNew Then
            txtInvNo.Locked = True
        Else
            txtInvNo.Locked = False
        End If

        If Mode = AddNewEdit Then
            Select Case rsHeader.Status
                Case adRecNew
                    sbRS.Panels(2) = "New"
                Case adRecModified
                    sbRS.Panels(2) = "Modified"
                Case Else
                    sbRS.Panels(2) = ""
            End Select
        Else: sbRS.Panels(2) = ""
        End If

        GetChild
        ShowInvoiceBalance
        
        If rsHeader!lCancelled = True Then
            sbRS.Panels(5) = "CANCELLED"
        Else: sbRS.Panels(5) = ""
        End If
    Else
        sbRS.Panels(1) = "Record: 0/0"
        sbRS.Panels(2) = ""
        txtInvNo.Locked = False
    End If

    If Mode = AddNewEdit Then
        dtgSI.Refresh
    End If

ErrorHandler:
    'Err.Number -2147217885
    'Description - Row handle referred to a deleted row or a row marked for deletion.
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

Private Sub Timer1_Timer()
    If Mode = AddNewEdit Then
        SSTab1.TabEnabled(1) = False
    Else
        SSTab1.TabEnabled(1) = True
    End If
End Sub

Private Sub txtCode_Change()
    txtName = ""
    Select Case Trim(cboType)
        Case "Supplier"
            txtName = GetValueFrTable("cName", "CLIENT_SUPPLIER", "cCode = '" & Trim(txtCode) & "'")
        Case "Employee"
            txtName = GetValueFrTable("cEmpName", "EMPLOYEE", "cEmpCode = '" & Trim(txtCode) & "'")
        Case Else
            txtName = GetValueFrTable("cName", "CLIENT_CUSTOMER", "cCode = '" & Trim(txtCode) & "'")
    End Select
    
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(txtName) <> "" Then
        If rsHeader.Status = adRecNew Then
            If (UCase(Trim(cboType)) = "INVOICE") Then
                If Not SICreditLimitOK Then
                    txtName = ""
                    txtMSCode = ""
                    txtPDCode = ""
                    txtSMCode = ""
                    cboTerms.ListIndex = -1
                    cboIntTerms.ListIndex = -1
                    Exit Sub
                End If
            End If
        End If
        rsHeader!cMSCode = GetValueFrTable("cMSCode", "CLIENT_CUSTOMER", "cCode = '" & Trim(txtCode) & "'")
        rsHeader!cPDCode = GetValueFrTable("cPDCode", "CLIENT_CUSTOMER", "cCode = '" & Trim(txtCode) & "'")
        If GetValueFrTable("lBit", "SYSTEM_OPTION", "cCode = 'CLNT_MAN_USERDFSMAN'") = True Then
            GetUser txtSMCode, txtSMName
        Else
            rsHeader!cSMan = GetValueFrTable("cSMan", "CLIENT_CUSTOMER", "cCode = '" & Trim(txtCode) & "'")
        End If
        rsHeader!cTerm = GetValueFrTable("cTerm", "CLIENT_CUSTOMER", "cCode = '" & Trim(txtCode) & "'")
        rsHeader!cIntTerm = GetValueFrTable("cIntTerm", "CLIENT_CUSTOMER", "cCode = '" & Trim(txtCode) & "'")
        'rsHeader!cDivision = GetValueFrTable("cPCCode", "CLIENT_CUSTOMER", "cCode = '" & Trim(txtCode) & "'")
        If Not lOverride Then txtRemarks.SetFocus
    Else
        txtMSCode = ""
        txtPDCode = ""
        txtSMCode = ""
        cboTerms.ListIndex = -1
        cboIntTerms.ListIndex = -1
    End If
End Sub



Private Sub txtCode_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(txtName) = "" And Trim(txtCode) <> "" Then cmdPickCode_Click
End Sub

Private Sub txtDocType_Change()
    If Trim(txtDocType) <> "" Or txtDocType <> vbNullString Then
    
        If GetValueFrTable("cValue", "PARAMETER_USER", "cType = 'SIDOCTYPE' AND cValue = '" & Trim(txtDocType) & "' ", False) <> "" Then
            cboDocType = Trim(txtDocType)
        Else: cboDocType.ListIndex = -1
        End If
    Else: cboDocType.ListIndex = -1
    End If
End Sub

Private Sub txtFreightAllow_Change()
    ComputeTotal
End Sub

Private Sub txtFreightCharges_Change()
    ComputeTotal
End Sub

Private Sub txtIntTerms_Change()
    If Trim(txtIntTerms) <> "" Or txtIntTerms <> vbNullString Then
        cboIntTerms = Trim(txtIntTerms)
    Else: cboIntTerms.ListIndex = -1
    End If
End Sub

Private Sub txtInvNo_LostFocus()
    'Does Code Already Exist
    If Mode = AddNewEdit Then
        If Trim(txtInvNo) = "" Then
            MsgBox "Empty primary input.", vbInformation, "ComUnion"
            PreviousTab frmComUnionMenuTab
            txtInvNo.SetFocus
        Else
            If rsHeader.Status <> adRecNew Then Exit Sub
            txtInvNo = Trim(txtInvNo)
            If IDExisting(rsHeader, "cInvNo", "SALES", Trim(rsHeader!cInvNo)) Then
                MsgBox "Sales invoice No. already exist.", vbInformation, "ComUnion"
'                PreviousTab frmComUnionMenuTab
                txtInvNo.SetFocus
            End If
        End If
    End If
End Sub

Private Sub txtLongDesc_KeyPress(KeyAscii As Integer)
    If Mode <> AddNewEdit Then Exit Sub
    If KeyAscii = 39 Then KeyAscii = 0 'Apostrophe {'}
    KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub

Private Sub txtLongDesc_LostFocus()
    txtLongDesc.Visible = False
    dtgSI.Col = 3
    dtgSI.SetFocus
End Sub

Private Sub txtMSCode_Change()
    txtMSDesc = ""
    txtMSDesc = GetValueFrTable("cDescription", "CLASSIFICATION", "cClassCode = '" & Trim(txtMSCode) & "' AND cType = 'MS'")
End Sub

Private Sub txtMSCode_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(txtMSDesc) = "" And Trim(txtMSCode) <> "" Then cmdPickMS_Click
End Sub

Private Sub txtPCCode_Change()
    txtPCDesc = ""
    txtPCDesc = GetValueFrTable("cDescription", "PROFITCENTER", "cPCCode = '" & Trim(txtPCCode) & "'")
End Sub

Private Sub txtPCCode_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(txtPCDesc) = "" And Trim(txtPCCode) <> "" Then cmdPickPC_Click
End Sub

Private Sub txtPDCode_Change()
    txtPDDesc = ""
    txtPDDesc = GetValueFrTable("cDescription", "CLASSIFICATION", "cClassCode = '" & Trim(txtPDCode) & "' AND cType = 'PD'")
End Sub

Private Sub txtPDCode_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(txtPDDesc) = "" And Trim(txtPDCode) <> "" Then cmdPickPD_Click
End Sub

Private Sub txtPaymentType_Change()
    If Trim(txtPaymentType) <> "" Or txtPaymentType <> vbNullString Then
        cboPaymentType = Trim(txtPaymentType)
    Else: cboPaymentType.ListIndex = -1
    End If
End Sub

Private Sub txtSMCode_Change()
    txtSMName = ""
    txtSMName = GetValueFrTable("cName", "SALESMAN", "cCode = '" & Trim(txtSMCode) & "'")
End Sub

Private Sub txtSMCode_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(txtSMName) = "" And Trim(txtSMCode) <> "" Then cmdPickSM_Click
End Sub

Private Sub txtTerms_Change()
    If Trim(txtTerms) <> "" Or txtTerms <> vbNullString Then
        cboTerms = Trim(txtTerms)
    Else: cboTerms.ListIndex = -1
    End If
End Sub

Private Sub txtType_Change()
    If Trim(txtType) <> "" Or txtType <> vbNullString Then
        cboType = Trim(txtType)
    Else: cboType.ListIndex = -1
    End If
End Sub

'Check if all mandatory fields are complete
Function MandatoryOK() As Boolean

    MandatoryOK = True

    If Trim(txtInvNo) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Invoice Number' is mandatory. Null value is not allowed.", vbInformation, "ComUnion"
        txtInvNo.SetFocus
        Exit Function
    End If
    
    If Trim(rsHeader!cType) <> "Consignment" Then
        ComputeAmount
        ComputeGross
    End If
    ComputeTotal
    
    If rsHeader.Status = adRecNew Then
        If IDExisting(rsHeader, "cInvNo", "SALES", Trim(rsHeader!cInvNo)) Then
            MandatoryOK = False
            MsgBox "Sales invoice No. already exist.", vbInformation, "ComUnion"
            txtInvNo.SetFocus
            Exit Function
        End If
    End If

    'Required fields
    If Trim(dtbDate.Text) = "__/__/____" Then
        MandatoryOK = False
        MsgBox "Field 'Transaction Date' is mandatory. Null value is not allowed.", vbInformation, "ComUnion"
        dtbDate.SetFocus
        Exit Function
    ElseIf Trim(txtType) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Type' is mandatory. Null value is not allowed.", vbInformation, "ComUnion"
        cboType.SetFocus
        Exit Function
    ElseIf Trim(txtCode) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Customer' is mandatory. Null value is not allowed.", vbInformation, "ComUnion"
        txtCode.SetFocus
        Exit Function
'    ElseIf Trim(txtMSCode) = "" Then
'        MandatoryOK = False
'        MsgBox "Field 'Market Segment' is mandatory. Null value is not allowed.", vbInformation, "ComUnion"
'        txtMSCode.SetFocus
        Exit Function
    ElseIf Trim(txtSMCode) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Salesman' is mandatory. Null value is not allowed.", vbInformation, "ComUnion"
        txtSMCode.SetFocus
        Exit Function
    ElseIf Trim(txtIntTerms) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Internal Terms' is mandatory. Null value is not allowed.", vbInformation, "ComUnion"
        cboIntTerms.SetFocus
        Exit Function
    ElseIf Trim(txtTerms) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Actual Terms' is mandatory. Null value is not allowed.", vbInformation, "ComUnion"
        cboTerms.SetFocus
        Exit Function
    ElseIf Trim(txtPaymentType) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Payment Type' is mandatory. Null value is not allowed.", vbInformation, "ComUnion"
        cboPaymentType.SetFocus
        Exit Function
    End If
    
    GetChild
    
    'Transaction without details
    If rsDetail.RecordCount = 0 Then
        MandatoryOK = False
        MsgBox "Cannot save transaction without details.", vbInformation, "ComUnion"
        dtgSI.SetFocus
        Exit Function
    End If
    
    GetChild
    
    If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
    Do Until rsDetail.EOF
        If rsDetail.Status = (adRecNew) Or rsDetail.Status = (adRecModified) Then
            If IsNull(rsDetail!cItemNo) Then
                rsDetail.Delete
            ElseIf Trim(rsDetail!cItemNo) = "" Then
                rsDetail.Delete
            Else: rsDetail.MoveNext
            End If
        Else: rsDetail.MoveNext
        End If
    Loop
    
    GetChild
    
    If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
    Do Until rsDetail.EOF
        If rsDetail!cWH = "" Then
            MandatoryOK = False
            MsgBox "Warehouse is required.", vbInformation, "ComUnion"
            Exit Function
        End If
        rsDetail.MoveNext
    Loop
    
    GetChild

    If rsDetail.RecordCount < 1 Then
        MsgBox "Cannot save transaction without details.", vbExclamation, "ComUnion"
        MandatoryOK = False
        Exit Function
    End If

End Function

'Filter detail recordset to header's primary
Private Sub GetChild()
    rsDetail.Filter = "cInvNo = '" & Trim(rsHeader!cInvNo) & "'"
End Sub

'Sets the form if record number is zero
Private Sub RSZero()
    sbRS.Panels(1) = "Record: 0/0"
    sbRS.Panels(2) = ""
    sbRS.Panels(4) = ""
    sbRS.Panels(5) = ""
    
    Set dtgSI.DataSource = Nothing
    dtgSI.Refresh
    
    Set FrmName = Me
    UnbindControls
    TextClearing
    FormLocking True
    
    If rsHeader.State = adStateOpen Then rsHeader.Close
    If rsDetail.State = adStateOpen Then rsDetail.Close
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, , , , , , , , , True, , , True
    
    txtInvNo.Locked = False
    txtInvNo.SetFocus
    
    Mode = Find
    
End Sub

Sub SearchObj(lEnable As Boolean)
    dtbDate.Enabled = lEnable
    cboType.Enabled = lEnable
    cboDocType.Enabled = lEnable
    cmdPickCode.Enabled = lEnable
    cmdPickMS.Enabled = lEnable
    cmdPickPD.Enabled = lEnable
    cmdPickSM.Enabled = lEnable
    cboIntTerms.Enabled = lEnable
    cboTerms.Enabled = lEnable
    cboPaymentType.Enabled = lEnable
End Sub

'Add DR Detals from picklist to details recordset
Public Sub AddDetailsFromList()
    
    GetChild
    
    With frmRefList.lvwList
        For i = 1 To .ListItems.Count
            If UCase(Trim(cboType)) = "INVOICE W/ DR" Then
                ListToGrid i
            Else
                If .ListItems(i).Checked = True Then
                    ListToGrid i
                End If
            End If
        Next i
    End With

    GetChild
    
    ComputeTotal
    EditDetail True

End Sub

'From pick list to datagrid
Sub ListToGrid(i As Integer)
Dim cSO, cSONO As String
Dim nSO_I As Long
Dim nDisc As Double
    
    cSONO = ""
    
    
    With frmRefList.lvwList
        rsDetail.AddNew
        rsDetail!cCompanyID = COID
        rsDetail!cInvNo = Trim(rsHeader!cInvNo)
        rsDetail!cRefNo = Trim(frmRefList.mRefPK)
        rsDetail!cItemNo = Trim(.ListItems(i).Text)
        rsDetail!cDesc = Trim(.ListItems(i).SubItems(1))
        rsDetail!cWH = Trim(.ListItems(i).SubItems(2))
        rsDetail!cUnit = Trim(.ListItems(i).SubItems(3))
        rsDetail!nQty = CDbl(.ListItems(i).SubItems(4))
        rsDetail!nPrice = CDbl(.ListItems(i).SubItems(5))
        rsDetail!nAmount = CDbl(.ListItems(i).SubItems(6))
        rsDetail!nRefIdentity = CDbl(.ListItems(i).SubItems(7))
        rsDetail!nFactor = CDbl(.ListItems(i).SubItems(8))
        rsDetail!nCost = CDbl(.ListItems(i).SubItems(9))
        rsDetail!nMargin = "0.00"
        rsDetail!nSDiscount = "0.00"
        rsDetail!nSAdjustment = "0.00"
        rsDetail!nSNet = rsDetail!nAmount
        rsDetail!cBarcodeID = Trim(.ListItems(i).SubItems(12))
        
        If (UCase(Trim(cboType)) = "INVOICE") Or (UCase$(Trim$(cboType)) = "CONSIGNMENT") Then
            cSO = Trim(frmRefList.mRefPK)
            nSO_I = CDbl(.ListItems(i).SubItems(7))
        Else
            cSO = GetValueFrTable("cRefNo", "DR_T", "cDRNo = '" & Trim(frmRefList.mRefPK) & "' AND nIdentity = '" & CDbl(.ListItems(i).SubItems(7)) & "'")
            nSO_I = GetValueFrTable("nRefIdentity", "DR_T", "cDRNo = '" & Trim(frmRefList.mRefPK) & "' AND nIdentity = '" & CDbl(.ListItems(i).SubItems(7)) & "'")
        End If
        
        rsDetail!cPricing = GetValueFrTable("cPricing", "SO_T", "cSONo = '" & Trim(cSO) & "' AND nIdentity = '" & nSO_I & "'")
        rsDetail!nUDPrice = GetValueFrTable("nPrice", "SO_T", "cSONo = '" & Trim(cSO) & "' AND nIdentity = '" & nSO_I & "'")
        rsDetail!cDiscount = GetValueFrTable("cDiscount", "SO_T", "cSONo = '" & Trim(cSO) & "' AND nIdentity = '" & nSO_I & "'")
        rsDetail!nTPC = GetValueFrTable("nTPC", "SO_T", "cSONo = '" & Trim(cSO) & "' AND nIdentity = '" & nSO_I & "'")
        rsDetail!nSMCom = GetValueFrTable("nSMCom", "SO_T", "cSONo = '" & Trim(cSO) & "' AND nIdentity = '" & nSO_I & "'")
        rsDetail!cCosting = GetValueFrTable("cCosting", "ITEM", "cItemNo = '" & Trim(rsDetail!cItemNo) & "'")
        
    End With
End Sub

'Datagrid state when adding/editing transactions
Sub EditDetail(bval As Boolean)
    If (UCase(Trim(cboType)) = "INVOICE") Or (UCase(Trim(cboType)) = "CONSIGNMENT") Then
        dtgSI.Columns(1).Button = bval
        dtgSI.Columns(5).Locked = Not bval
        dtgSI.Columns(6).Locked = Not bval
    ElseIf UCase$(Trim$(cboType)) = "SAMPLE/DEMO" Then
        dtgSI.Columns(1).Button = bval
        dtgSI.Columns(5).Locked = Not bval
        dtgSI.Columns(6).Locked = Not bval
    ElseIf UCase$(Trim$(cboType)) = "INVOICE W/ DR" Then
        dtgSI.Columns(6).Locked = Not bval
    End If
End Sub

'Computes total amount per detail line
Private Sub ComputeAmount()
Dim nAmount As Double
On Error Resume Next
    If Mode <> AddNewEdit Then Exit Sub
    With dtgSI
        If Trim(rsHeader!cType) <> "Consignment" Then
        nAmount = IIf(IsNull(.Columns(6).Value), 0, .Columns(6).Value) * _
                    IIf(IsNull(.Columns(5).Value), 0, .Columns(5).Value)
        .Columns(7).Text = Format(nAmount, "###,##0.#0")
        Else
            nAmount = IIf(IsNull(.Columns(7).Value), 0, .Columns(7).Value)
            .Columns(7).Text = Format(nAmount, "###,##0.#0")
        End If
    End With
End Sub

'Computes gross per detail line
Private Sub ComputeGross()
Dim nGross As Double
On Error Resume Next
    If Mode <> AddNewEdit Then Exit Sub
    With dtgSI
        If Trim(rsHeader!cType) <> "Consignment" Then
        nGross = IIf(IsNull(.Columns(6).Value), 0, .Columns(6).Value) * _
                    IIf(IsNull(.Columns(5).Value), 0, .Columns(5).Value) - _
                    IIf(IsNull(.Columns(12).Value), 0, .Columns(12).Value) - _
                    IIf(IsNull(.Columns(13).Value), 0, .Columns(13).Value) - _
                    IIf(IsNull(.Columns(14).Value), 0, .Columns(14).Value)
        .Columns(15).Text = Format(nGross, "###,##0.#0")
        Else
            nGross = IIf(IsNull(.Columns(7).Value), 0, .Columns(7).Value) - _
                    IIf(IsNull(.Columns(12).Value), 0, .Columns(12).Value) - _
                    IIf(IsNull(.Columns(13).Value), 0, .Columns(13).Value) - _
                    IIf(IsNull(.Columns(14).Value), 0, .Columns(14).Value)
            .Columns(15).Text = Format(nGross, "###,##0.#0")
        End If
        rsDetail!nSNet = Format(nGross, "###,##0.#0")
    End With
End Sub

'Gross amount
Public Sub ComputeTotal()
Dim n, nTPC As Double
    
On Error Resume Next
    
    If Mode <> AddNewEdit Then Exit Sub
    
    
    n = 0
    nTPC = 0
    Set rs = New Recordset
    Set rs = rsDetail.Clone
    rs.Filter = "cInvNo = '" & Trim(rsHeader!cInvNo) & "'"

'    rs.MoveFirst
'    Do Until rs.EOF
'        nTPC = nTPC + IIf(IsNull(rs!nTPC), 0, rs!nTPC)
'        n = n + IIf(IsNull(rs!nAmount), 0, rs!nAmount)
'        rs.MoveNext
'    Loop
'
    rs.MoveFirst
    Do Until rs.EOF
        nTPC = nTPC + IIf(IsNull(rs!nTPC), 0, rs!nTPC)
        n = n + IIf(IsNull(rs!nSNet), 0, rs!nSNet)
        ' Format(5459.4, "##,##0.00")

        MsgBox nTPC
        MsgBox n
        rs.MoveNext
    Loop
    Set rs = Nothing
    
    n = n - CDbl(txtFreightAllow) + CDbl(txtFreightCharges)
    
    rsHeader!nGross = n - CDbl(rsHeader!nDiscount) '- CDbl(rsHeader!nSAdjustment) - CDbl(rsHeader!nSDiscount) 'Jomz
    rsHeader!nBalance = n - CDbl(rsHeader!nDiscount)
    rsHeader!nTPCGross = nTPC
    txtBalance = n - CDbl(rsHeader!nDiscount) '- CDbl(rsHeader!nSAdjustment) - CDbl(rsHeader!nSDiscount) 'Jomz
End Sub

'Inserts into DR & DR_T tables
Private Function SIToDR() As Boolean
Dim rsDR As New ADODB.Recordset
Dim rsDR_T As New ADODB.Recordset
Dim rsTRIPTICKET As New ADODB.Recordset
Dim rsTRIPTICKET_T As New ADODB.Recordset
Dim cSO, cSO_T As String
Dim nSO_I As Long

On Error GoTo FunctionExit
    
    SIToDR = False

    cString = "SI-" & Trim$(rsHeader!cInvNo)
    cSO = rsDetail!cRefNo
    
    cn.Execute ("DELETE DR_T WHERE cCompanyID = '" & COID & "' AND cDRNo = '" & Trim(cString) & "'")
    cn.Execute ("DELETE DR WHERE cCompanyID = '" & COID & "' AND cDRNo = '" & Trim(cString) & "'")
    
    GetChild
    
    OpenRecordset rsDR, "*", "DR", "WHERE 1 = 0"
    OpenRecordset rsDR_T, "*", "DR_T", "WHERE 1 = 0"
    
    With rsDR
        .AddNew
        !cCompanyID = COID
        !cDRNo = Trim$(cString)
        !dDate = rsHeader!dDate
        !cType = "Auto-DR"
        !cRemarks = "Auto-DR for " & Trim(rsHeader!cType)
        !cDelCode = Trim$(rsHeader!cCode)
        !cInvNo = Trim$(rsHeader!cInvNo)
        !cGPNo = Trim$(cString)
        !nGross = rsHeader!nGross
        !cPCCode = Trim(txtPCCode)
        !nFreightCharges = CDbl(txtFreightCharges)
        !nFreightAllow = CDbl(txtFreightAllow)
    End With
    
    Do While Not rsDetail.EOF
        With rsDR_T
            .AddNew
            !cCompanyID = COID
            !cDRNo = Trim(cString)
            !cRefNo = Trim(rsDetail!cRefNo)
            !nRefIdentity = rsDetail!nRefIdentity
            !cWH = Trim$(rsDetail!cWH)
            !cItemNo = Trim(rsDetail!cItemNo)
            !cDesc = Trim$(rsDetail!cDesc)
            !cLongDesc = IIf(IsNull(rsDetail!cLongDesc), "", Trim(rsDetail!cLongDesc))
            !cUnit = Trim(rsDetail!cUnit)
            !nQty = rsDetail!nQty
            !nPrice = rsDetail!nPrice
            !nAmount = rsDetail!nAmount
            !nCost = rsDetail!nCost
            !cCosting = rsDetail!cCosting
            !cBatchID = rsDetail!cBatchID
            !nFactor = rsDetail!nFactor
            !cBarcodeID = Trim(GetValueFrTable("cBarcodeID", "SO_T", "cSONo = '" & Trim(rsDetail!cRefNo) & "' and cItemNo = '" & Trim(rsDetail!cItemNo) & "'")) & ""
        End With
        rsDetail.MoveNext
    Loop
    
    rsDR.UpdateBatch adAffectAll
    rsDR_T.UpdateBatch adAffectAll
    
    Set rsDR = Nothing
    Set rsDR_T = Nothing
    
    SIToDR = True
    
FunctionExit:
    Exit Function
    
End Function

'Inserts into DR & DR_T tables
Private Function SIToDR_Supp() As Boolean
Dim rsDR As New ADODB.Recordset
Dim rsDR_T As New ADODB.Recordset
Dim cSO, cSO_T As String
Dim nSO_I As Long

On Error GoTo FunctionExit
    
    SIToDR_Supp = False

    cString = "SI-" & Trim$(rsHeader!cInvNo)
    cSO = rsDetail!cRefNo
    
    cn.Execute ("DELETE DR_T WHERE cCompanyID = '" & COID & "' AND cDRNo = '" & Trim(cString) & "'")
    cn.Execute ("DELETE DR WHERE cCompanyID = '" & COID & "' AND cDRNo = '" & Trim(cString) & "'")
    
    GetChild
    
    OpenRecordset rsDR, "*", "DR", "WHERE 1 = 0"
    OpenRecordset rsDR_T, "*", "DR_T", "WHERE 1 = 0"
    
    With rsDR
        .AddNew
        !cCompanyID = COID
        !cDRNo = Trim$(cString)
        !dDate = rsHeader!dDate
        !cType = "Supplier"
        !cDelCode = Trim$(rsHeader!cCode)
        !cInvNo = Trim$(rsHeader!cInvNo)
        !nGross = rsHeader!nGross
        !cPCCode = Trim(txtPCCode)
    End With

    Do While Not rsDetail.EOF
        With rsDR_T
            .AddNew
            !cCompanyID = COID
            !cDRNo = Trim(cString)
            !cRefNo = Trim(rsDetail!cRefNo)
            !nRefIdentity = rsDetail!nRefIdentity
            !cWH = Trim$(rsDetail!cWH)
            !cItemNo = Trim(rsDetail!cItemNo)
            !cDesc = Trim$(rsDetail!cDesc)
            !cLongDesc = IIf(IsNull(rsDetail!cLongDesc), "", Trim(rsDetail!cLongDesc))
            !cUnit = Trim(rsDetail!cUnit)
            !nQty = rsDetail!nQty
            !nPrice = rsDetail!nPrice
            !nAmount = rsDetail!nAmount
            !nCost = rsDetail!nCost
            !cCosting = rsDetail!cCosting
            !cBatchID = rsDetail!cBatchID
            !nFactor = rsDetail!nFactor
        End With
        rsDetail.MoveNext
    Loop

    rsDR.UpdateBatch adAffectAll
    rsDR_T.UpdateBatch adAffectAll
    
    Set rsDR = Nothing
    Set rsDR_T = Nothing
    
    SIToDR_Supp = True
    
FunctionExit:
    Exit Function
    
End Function

'Inserts into WRR & WRR_T tables
Private Function SIToWRR() As Boolean
Dim rsWRR As New ADODB.Recordset
Dim rsWRR_T As New ADODB.Recordset
Dim cSO As String, cSO_T As String
Dim nSO_I As Long

On Error GoTo FunctionExit
    
    SIToWRR = False
    rsDetail.MoveFirst
    cString = "SI-" & Trim$(rsHeader!cInvNo)
    cSO = rsDetail!cRefNo
    
    cn.Execute ("DELETE WRR_T WHERE cCompanyID = '" & COID & "' AND cWRRNo = '" & Trim(cString) & "'")
    cn.Execute ("DELETE WRR WHERE cCompanyID = '" & COID & "' AND cWRRNo = '" & Trim(cString) & "'")
    
    GetChild
    
    OpenRecordset rsWRR, "*", "WRR", "WHERE 1 = 0"
    OpenRecordset rsWRR_T, "*", "WRR_T", "WHERE 1 = 0"
    
    With rsWRR
        .AddNew
        !cCompanyID = COID
        !cPCCode = Trim(txtPCCode)
        !cWRRNo = Trim$(cString)
        !dDate = rsHeader!dDate
        !cReturnType = "Auto-Jobber"
        !cType = "Auto-Jobber"
        !cCode = GetValueFrTable("cDCode", "SO", "cSONo = '" & Trim(cSO) & "'")
        !cName = GetValueFrTable("cName", "CLIENT_CUSTOMER", "cCode = '" & Trim(!cCode) & "'")
        !cAddress = GetAddress("CLIENT_CUSTOMER", "cCode = '" & Trim(!cCode) & "'") & ""
        !cContact = GetValueFrTable("cContact", "SO", "cSONo = '" & Trim(cSO) & "'")
        !cTerms = rsHeader!cTerm
        !cRemarks = "Auto JOBBER"
        !nGross = rsHeader!nGross
    End With

    Do While Not rsDetail.EOF
        With rsWRR_T
            .AddNew
            !cCompanyID = COID
            !cWRRNo = Trim(cString)
            !cRefNo = rsHeader!cInvNo
            !nRefIdentity = rsDetail!nRefIdentity
            !cWH = Trim(rsDetail!cWH)
            !cItemNo = Trim(rsDetail!cItemNo)
            !cDesc = Trim(rsDetail!cDesc)
            !cUnit = Trim(rsDetail!cUnit)
            !nQty = rsDetail!nQty
            !nPrice = rsDetail!nPrice
            !nAmount = rsDetail!nAmount
            !nCost = rsDetail!nCost
            !nFactor = rsDetail!nFactor
        End With
        rsDetail.MoveNext
    Loop

    rsWRR.UpdateBatch adAffectAll
    rsWRR_T.UpdateBatch adAffectAll
    
    Set rsWRR = Nothing
    Set rsWRR_T = Nothing
    
    SIToWRR = True
    
FunctionExit:
    Exit Function
End Function

Private Function SIToAR() As Boolean
Dim rsAR As New ADODB.Recordset
Dim rsAR_T As New ADODB.Recordset
Dim cSO As String, cSO_T As String
Dim nSO_I As Long

On Error GoTo FunctionExit
    SIToAR = False
    cString = "SI-" & Trim$(rsHeader!cInvNo)
    'cSO = rsDetail!cRefNo
    cn.Execute ("DELETE AR_T WHERE cCompanyID = '" & COID & "' AND cTranNo = '" & Trim(cString) & "'")
    cn.Execute ("DELETE AR WHERE cCompanyID = '" & COID & "' AND cTranNo = '" & Trim(cString) & "'")
    
    GetChild
    
    OpenRecordset rsAR, "*", "AR", "WHERE 1 = 0"
    OpenRecordset rsAR_T, "*", "AR_T", "WHERE 1 = 0"
    With rsAR
        .AddNew
        !cCompanyID = COID
        !cTranNo = Trim$(cString)
        !dDate = rsHeader!dDate
        !cType = "Credit"
        !lSalesReturn = 1
        !cWRRNo = Trim$(cString)
        !cCode = GetValueFrTable("cDCode", "SO", "cSONo = '" & Trim(cSO) & "'")
        !cPCCode = Trim(txtPCCode)
        !cRemarks = "Auto CM from SI Jobber"
        !nGross = rsHeader!nGross
    End With

    Do While Not rsDetail.EOF
        With rsAR_T
            .AddNew
            !cCompanyID = COID
            !cTranNo = Trim$(cString)
            !cInvNo = Trim$(rsHeader!cInvNo)
            !cAcctNo = GetValueFrTable("cValue", "SYSTEM_OPTION", "cCode = 'DEF_AR'")
            !cTitle = GetValueFrTable("cTitle", "ACCOUNT", "cAcctNo = '" & Trim(!cAcctNo) & "'")
            !nCredit = rsHeader!nGross
            !cRemarks = "Auto from SI Jobber"
        End With
        rsDetail.MoveNext
    Loop

    rsDetail.MoveFirst
    Do While Not rsDetail.EOF
        With rsAR_T
            .AddNew
            !cCompanyID = COID
            !cTranNo = Trim$(cString)
            !cInvNo = Trim$(rsHeader!cInvNo)
            !cAcctNo = GetValueFrTable("cValue", "SYSTEM_OPTION", "cCode = 'DEF_RETURN'")
            !cTitle = GetValueFrTable("cTitle", "ACCOUNT", "cAcctNo = '" & Trim(!cAcctNo) & "'")
            !nDebit = rsHeader!nGross
            !cRemarks = "Auto from SI Jobber"
        End With
        rsDetail.MoveNext
    Loop

    rsAR.UpdateBatch adAffectAll
    rsAR_T.UpdateBatch adAffectAll
    
    Set rsAR = Nothing
    Set rsAR_T = Nothing
    
    SIToAR = True
    
FunctionExit:
    Exit Function
    
End Function

'Update cInvNo field on DR table
Private Function UpdateDRSI() As Boolean
On Error GoTo FunctionExit
    
    UpdateDRSI = False
    
    Do While Not rsDetail.EOF
        cn.Execute ("UPDATE DR SET cInvNo = '" & Trim(rsHeader!cInvNo) & "' WHERE cDRNo = '" & Trim(rsDetail!cRefNo) & "' AND cCompanyID = '" & COID & "'")
        rsDetail.MoveNext
    Loop
    
    UpdateDRSI = True

FunctionExit:
    Exit Function

End Function

'Show the balances of each sales invoice
'Binding of the textboxex was disabled
Private Sub ShowInvoiceBalance()
Dim rsBalance As New Recordset

    If Mode = AddNewEdit Then Exit Sub
    
    sSQL = "SELECT *, ISNULL((nSales - nReturns - nPaid - nCredit + nDebit), 0) AS nBalance " & _
            "FROM V_SalesBalanceInquiry WHERE cInvNo = '" & rsHeader!cInvNo & "' AND cCompanyID = '" & COID & "'"
    rsBalance.Open sSQL, cn, adOpenForwardOnly, adLockReadOnly
    
    txtDebit = 0
    txtCredit = 0
    txtReturns = 0
    txtPayment = 0
    txtBalance = 0
    
    If rsBalance.RecordCount <> 0 Then
        txtDebit = rsBalance!nDebit
        txtCredit = rsBalance!nCredit
        txtReturns = rsBalance!nReturns
        txtPayment = rsBalance!nPaid
        txtBalance = rsBalance!nBalance
    End If
    
    Set rsBalance = Nothing
    
End Sub

Private Function AllowEdit() As Boolean
    AllowEdit = True
    
    'Cannot edit if transaction already has a collection reference
    If GetValueFrTable("cInvNo", "PR_T", "cInvNo = '" & Trim(rsHeader!cInvNo) & "'") <> "" Then
        MsgBox "Cannot edit Invoice with collection.", vbCritical + vbExclamation, "ComUnion"
        AllowEdit = False
        Exit Function
    ElseIf UCase(Trim(rsHeader!cType)) = "AUTO-INVOICE" Then
        MsgBox "Cannot EDIT Auto-generated Invoice.", vbInformation, "ComUnion"
        AllowEdit = False
        Exit Function
    End If
    
End Function

Private Function AllowDelete(sAction As String) As Boolean
    AllowDelete = True
    
    'Cannot delete if transaction already has a collection reference
    If GetValueFrTable("cInvNo", "PR_T", "cInvNo = '" & Trim(rsHeader!cInvNo) & "'") <> "" Then
        MsgBox "Cannot " & sAction & " transaction with collection.", vbCritical + vbExclamation, "ComUnion"
        AllowDelete = False
        Exit Function
    ElseIf UCase(Trim(rsHeader!cType)) = "AUTO-INVOICE" Then
        MsgBox "Cannot DELETE Auto-generated Invoice. " & vbCr & _
        "Please DELETE Source Delivery Reciept.", vbInformation, "ComUnion"
        AllowDelete = False
        Exit Function
    ElseIf GetValueFrTable("cInvNo", "AR_T", "cInvNo = '" & Trim(rsHeader!cInvNo) & "'") <> "" Then
        MsgBox "Cannot DELETE Invoice with CM/DM Adjustments.", vbInformation, "ComUnion"
        AllowDelete = False
        Exit Function
    ElseIf GetValueFrTable("cRefNo", "WRR_T", "cRefNo = '" & Trim(rsHeader!cInvNo) & "'") <> "" Then
        MsgBox "Cannot DELETE Invoice with Receiving Report.", vbInformation, "ComUnion"
        AllowDelete = False
        Exit Function

    End If
    
    'Delete existing reference delivery receipt for this transaction
    If (UCase(Trim(cboType)) = "INVOICE") Or (UCase(Trim(cboType)) = "CONSIGNMENT") Then
        If MsgBox("Transaction type is 'Sales without DR'. Reference delivery receipt for this transaction will also be deleted. Proceed anyway?", vbCritical + vbOKCancel, "ComUnion") = vbCancel Then
            AllowDelete = False
            Exit Function
        End If
        cn.Execute ("DELETE DR_T WHERE cDRNo = 'SI-" & Trim$(rsHeader!cInvNo) & "' AND cCompanyID = '" & COID & "'")
        cn.Execute ("DELETE DR WHERE cDRNo = 'SI-" & Trim$(rsHeader!cInvNo) & "' AND cCompanyID = '" & COID & "'")
    Else
        cn.Execute ("UPDATE DR SET cInvNo = NULL WHERE cInvNo = '" & Trim$(rsHeader!cInvNo) & "' AND cCompanyID = '" & COID & "'")
    End If
    
    cn.Execute ("DELETE WRR_T WHERE cWRRNo = 'SI-" & Trim$(rsHeader!cInvNo) & "' AND cCompanyID = '" & COID & "'")
    cn.Execute ("DELETE WRR WHERE cWRRNo = 'SI-" & Trim$(rsHeader!cInvNo) & "' AND cCompanyID = '" & COID & "'")
    cn.Execute ("DELETE AR_T WHERE cTranNo = 'SI-" & Trim$(rsHeader!cInvNo) & "' AND cCompanyID = '" & COID & "'")
    cn.Execute ("DELETE AR WHERE cTranNo = 'SI-" & Trim$(rsHeader!cInvNo) & "' AND cCompanyID = '" & COID & "'")

End Function

'Checks the credit status of the client
Function SICreditLimitOK() As Boolean
Dim sCode, sPCCode As String
Dim lCHold As Boolean
    
    If Not GetValueFrTable("lBit", "SYSTEM_OPTION", "cCode = 'CL_CHECKING_SI'") Then
        SICreditLimitOK = True
        Exit Function
    End If
    
    MousePointer = vbHourglass
    FormWaitShow App.Path & "\Transmit.avi", "Checking Credit Limit Balance . . ."

    sCode = Trim(txtCode)
    
    cn.CommandTimeout = 600
    If Not GetValueFrTable("lGroupLimit", "CLIENT_CUSTOMER", "cCode = '" & sCode & "'") Then
        'Query for independent client
        sSQL = "SELECT cCompanyID, cCode, SUM(nLimit) AS nLimit, SUM(nAR) AS nAR, SUM(nARPastDue) AS nARPastDue, " & _
                "SUM(nPDC) AS nPDC, SUM(CAST(lHold AS INT)) AS nHold, SUM(nBounced) AS nBounced, " & _
                "SUM(nSOAmtLeft) AS nSOAmtLeft, SUM(nLimitBalance) AS nLimitBalance " & _
                "From V_CG " & _
                "WHERE cCode = '" & sCode & "' AND cCompanyID = '" & COID & "'" & _
                "GROUP BY cCompanyID, cCode"
    Else
        sPCCode = GetValueFrTable("cGroupCode", "CLIENT_CUSTOMER", "cCode = '" & sCode & "'")
        lCHold = GetValueFrTable("lHold", "CLIENT_CUSTOMER", "cCode = '" & sCode & "'")
        'Query for customer affecting parent company
        sSQL = "SELECT cCompanyID, cGroupCode, SUM(nLimit) AS nLimit, SUM(nAR) AS nAR, SUM(nARPastDue) AS nARPastDue, " & _
                "SUM(nPDC) AS nPDC, " & IIf(lCHold, "1", "0") & " AS nHold, SUM(nBounced) AS nBounced, " & _
                "SUM(nSOAmtLeft) AS nSOAmtLeft, SUM(nLimit - nAR - nPDC - nSOAmtLeft) AS nLimitBalance " & _
                "From V_CG_PC " & _
                "WHERE cGroupCode = '" & sPCCode & "' AND cCompanyID = '" & COID & "'" & _
                "GROUP BY cCompanyID, cGroupCode"
    End If
    
    Set rs = New Recordset
    rs.Open sSQL, cn, adOpenForwardOnly, adLockReadOnly
    cn.CommandTimeout = 120
    
    If rs.RecordCount > 0 Then
        nLimit = rs!nLimit
        nAR = rs!nAR
        nARPastDue = rs!nARPastDue
        nPDC = rs!nPDC
        nHold = rs!nHold
        nBounced = rs!nBounced
        nSOAmtLeft = rs!nSOAmtLeft
        nLimitBalance = rs!nLimitBalance
    Else
        nLimit = 0
        nAR = 0
        nARPastDue = 0
        nPDC = 0
        nHold = 0
        nBounced = 0
        nSOAmtLeft = 0
        nLimitBalance = 0
    End If
    
    'Is Credit OK?
    Dim cHold, cOCL, cPDAR, cRTC As String
    
    SICreditLimitOK = True
    If nHold > 0 Then
        cHold = "Customer on Hold"
        SICreditLimitOK = False
    End If
    If nLimitBalance < 0 Then
        cOCL = "Over Credit Limit [Php " & Format((-1 * nLimitBalance), "#,##0.#0") & "]"
        SICreditLimitOK = False
    End If
    If nARPastDue > 0 Then
        cPDAR = "With Past Due A/R [Php " & Format(nARPastDue, "#,##0.#0") & "]"
        SICreditLimitOK = False
    End If
    If nBounced > 0 Then
        cRTC = "With Bounced Check"
        SICreditLimitOK = False
    End If

    FormWaitHide
    MousePointer = vbDefault
    
    lOverride = False
    
    If Not SICreditLimitOK Then
        MsgBox "Cannot proceed transaction with customer " & sCode & " due to following reason/s:" & vbCr & _
               cHold & IIf((cOCL <> ""), " | " & cOCL, "") & _
               IIf((cPDAR <> ""), " | " & cPDAR, "") & _
               IIf((cRTC <> ""), " | " & cRTC, ""), vbCritical, Me.Caption
        If nBounced = 0 Then
            RepName = Trim(txtInvNo)
            frmOverride.mOverridingType = O_SI
            frmOverride.Show vbModal
            If gAction = G_OK Then
                lOverride = True
                SICreditLimitOK = True
                cmdPickSM.SetFocus
                Exit Function
            Else
                txtCode = ""
                txtCode.SetFocus
            End If
        Else
            txtCode = ""
            txtCode.SetFocus
        End If
    End If
    
End Function

Sub GetCtrlNo()
Dim lCtrlNoOK As Boolean

    If GetValueFrTable("lFormat", "PARAMETER_USER", "cValue = '" & Trim(cboDocType) & "' AND cType = 'SIDOCTYPE' ") <> True Then Exit Sub
    
    strNo = Trim(GetValueFrTable("cSeries", "PARAMETER_USER", "cValue = '" & Trim(cboDocType) & "' AND cType = 'SIDOCTYPE' "))
    
    X = ""
    For i = 1 To Trim(GetValueFrTable("nPlaces", "PARAMETER_USER", "cValue = '" & Trim(cboDocType) & "' AND cType = 'SIDOCTYPE' ")) - Len(Trim(GetValueFrTable("cSeries", "PARAMETER_USER", "cValue = '" & Trim(cboDocType) & "' AND cType = 'SIDOCTYPE' ")))
        X = "0" + X
    Next i
        
    Do Until lCtrlNoOK
        If IDExisting(rsHeader, "cInvNo", "SALES", Left(strNo, 5) + Format(CStr((CInt(Right(strNo, 4)) + 1)), X)) Then
            strNo = Left(strNo, 5) + Format(CStr((CInt(Right(strNo, 4)) + 1)), X)
        Else: lCtrlNoOK = True
        End If
    Loop
    
    strNo = Trim(Int(strNo) + 1)
    sType = Trim(GetValueFrTable("cPrefix", "PARAMETER_USER", "cValue = '" & Trim(cboDocType) & "' AND cType = 'SIDOCTYPE' "))
    txtInvNo = sType + X + strNo
End Sub

Private Function GetSearchString() As String
On Error GoTo ErrorHandler
Dim sWhere As String

    GetSearchString = True

    If Trim$(txtInvNo.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cInvNo LIKE '" & Trim$(txtInvNo.Text) & "%'"
    End If

    If Trim$(dtbDate.Text) <> "__/__/____" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " dDate = '" & Trim$(dtbDate.Text) & "'"
    End If
    
    If Trim$(txtType.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cType LIKE '" & Trim$(txtType.Text) & "%'"
    End If
    
    If Trim$(txtDocType.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cDocType LIKE '" & Trim$(txtDocType.Text) & "%'"
    End If
    
    If Trim$(txtCode.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cCode LIKE '" & Trim$(txtCode.Text) & "%'"
    End If
    
    If Trim$(txtMSCode.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cMSCode LIKE '" & Trim$(txtMSCode.Text) & "%'"
    End If
    
    If Trim$(txtPDCode.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cPDCode LIKE '" & Trim$(txtPDCode.Text) & "%'"
    End If
    
    If Trim(txtSMCode.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cSMan LIKE '" & Trim$(txtSMCode.Text) & "%'"
    End If
    
    If Trim(txtIntTerms.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cIntTerm LIKE '" & Trim$(txtIntTerms.Text) & "%'"
    End If
    
    If Trim(txtTerms.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cTerm LIKE '" & Trim$(txtTerms.Text) & "%'"
    End If
    
    If Trim(txtPaymentType.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cPayType LIKE '" & Trim$(txtPaymentType.Text) & "%'"
    End If
    
    GetSearchString = Trim$(sWhere)

    Exit Function
ErrorHandler:
    GetSearchString = "ERROR"
End Function

'Check system generated number before saving
Function CheckCtrlNo() As Boolean
Dim lCtrlNoOK As Boolean
Dim strNewNo As String
Dim strNewDRNo As String
Dim sTrap

On Error GoTo TheSource

    CheckCtrlNo = False
    lChangedTranNo = False
    
    If IDExisting(rsHeader, "cInvNo", "SALES", rsHeader!cInvNo) Then
        'strNewNo = Left(txtDRNo, 5) & (Format(Right(txtDRNo, 4) - 1, X))
        strNewNo = sType + X + strNo
        
        sTrap = Trim(GetValueFrTable("cSeries", "PARAMETER_USER", "cValue = '" & Trim(cboDocType) & "' AND cType = 'SIDOCTYPE' "))
        
        Do Until lCtrlNoOK
            If IDExisting(rsHeader, "cInvNo", "SALES", Left(strNewNo, 5) + Format(CStr((CInt(Right(strNewNo, 4)) + 1)), X)) Then
                strNewNo = Left(strNewNo, 5) + Format(CStr((CInt(Right(strNewNo, 4)) + 1)), X)
            Else: lCtrlNoOK = True
            End If
        Loop
        
        strNewDRNo = strNewNo
        
        GetChild
        
        rsHeader!cInvNo = strNewDRNo
        If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
        Do Until rsDetail.EOF
            rsDetail!cInvNo = strNewDRNo
            rsDetail.MoveNext
        Loop
        
        GetChild
        
        strNo = Trim(Int(sTrap) + 1)
    End If
    
    CheckCtrlNo = True
    
TheSource:
    If Not CheckCtrlNo Then
        If MsgBox("Record cannot be updated. Transaction number already exists. " & vbCr & _
                "Current transaction number may have been used by other user/s since last read." & vbCr & _
                "Do you want to assign another number?", vbYesNo + vbInformation, "ComUnion") = vbYes Then
            frmChangeTranNo.mType = Change_DRNo
            frmChangeTranNo.Show vbModal
        Else
            MsgBox "Transaction will be undone.", vbInformation, "ComUnion"
            TBUndoAll
        End If
    Else: lChangedTranNo = True
    End If
End Function

'Update system generated number
Sub UpdateCtrlNo()
On Error GoTo TheSource

    If GetValueFrTable("lFormat", "PARAMETER_USER", "cValue = '" & Trim(cboDocType) & "' AND cType = 'SIDOCTYPE' ") <> True Then Exit Sub
   
    If Not lChangedTranNo Then
        sSQL = "UPDATE PARAMETER_USER SET cSeries = '" & Trim(strNo) & "' WHERE cValue = '" & Trim(cboDocType) & "' AND cType = 'SIDOCTYPE' AND cCompanyID = '" & COID & "'"
        cn.Execute sSQL
    End If
    
TheSource:
    Exit Sub
End Sub


'Change Transaction Number
Sub ChangeTranNo(strTranNo As String)
    GetChild
    
    rsHeader!cInvNo = strTranNo
    If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
    Do Until rsDetail.EOF
        rsDetail!cInvNo = strTranNo
        rsDetail.MoveNext
    Loop
    
    GetChild
End Sub

'Public Sub ShowForm(sTranNo As String)
'    If Mode = Find Then
'
'        OpenNewConnection connHeader
'        OpenNewConnection connDetail
'
'        Set rsHeader = Nothing
'        Set rsDetail = Nothing
'        Set rsHeader = New ADODB.Recordset
'        Set rsDetail = New ADODB.Recordset
'
'        OpenRecordsetWithCN rsDetail, "*", "SALES_T", connDetail, "WHERE cInvNo = '" & Trim(sTranNo) & "'"
'        OpenRecordsetWithCN rsHeader, "*", "SALES", connHeader, "WHERE cInvNo = '" & Trim(sTranNo) & "' AND cType <> 'Van Selling'"
'
'        Set FrmName = Me
'        FormLocking True
'
'        If rsHeader.RecordCount = 0 Then
'            FormWaitHide
'            MsgBox "No matching record/s found.", vbInformation, "ComUnion Search"
'            RSZero
'            FormSearch True
'            SearchObj True
'            Mode = Find
'            Exit Sub
'        End If
'            SetDataSource
'            SetDataField
'            txtInvNo.BackColor = &HE0FFFF
'            Mode = Normal
'            oBar.BitEnabled Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , , , , True, True, , True, True
'
'    End If
'End Sub
